D. Duff in Beach
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/588/problem/D
Description
While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, a0, ..., an - 1 that b can be build from a with formula: bi = ai mod n where a mod b denoted the remainder of dividing a by b.
Duff is so curious, she wants to know the number of subsequences of b like bi1, bi2, ..., bix (0 ≤ i1 < i2 < ... < ix < l), such that:
- 1 ≤ x ≤ k
- For each 1 ≤ j ≤ x - 1,
- For each 1 ≤ j ≤ x - 1, bij ≤ bij + 1. i.e this subsequence is non-decreasing.
Since this number can be very large, she want to know it modulo 109 + 7.
Duff is not a programmer, and Malek is unavailable at the moment. So she asked for your help. Please tell her this number.
Input
The first line of input contains three integers, n, l and k (1 ≤ n, k, n × k ≤ 106 and 1 ≤ l ≤ 1018).
The second line contains n space separated integers, a0, a1, ..., an - 1 (1 ≤ ai ≤ 109 for each 0 ≤ i ≤ n - 1).
Output
Sample Input
3 5 3 5 9 1
Sample Output
10
HINT
题意
给你n,l,k,然后就是告诉你b有l长度,其中是由a不停重复得到的
然后问你一共有多少个满足条件的序列存在
条件如下:
1.这个序列的长度大于等于1,小于等于k
2.这个序列在每一个块中只能选择一个数,并且都必须选择在连续的块中
3.这个序列是单调不降的
题解:
dp,由于n*k<=1e6,所以我们简单的推断是dp[n][k]的,表示第i个数长度为k的序列有多少个
其实这道题和分块差不多,在块外就用dp瞎转移
块内就暴力就好了……
只要把这个数据过了就好了
3 100 3
1 1 1
注意是upper_bound这个东西
代码:
#include#include #include #include