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.
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).
Print the answer modulo 1 000 000 007 in one line.
3 5 3 5 9 1
10
5 10 3 1 2 3 4 5
25
离散化 + dp
/*======================================================
# Author: whai
# Last modified: 2015-10-23 13:27
# Filename: b.cpp
======================================================*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define LL __int64
#define PB push_back
#define P pair<int, int>
#define X first
#define Y second
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int a[N];
int b[N], b_tot;
void lsh(int a[], int n) {
for(int i = 0; i < n; ++i)
b[i] = a[i];
sort(b, b + n);
b_tot = unique(b, b + n) - b;
for(int i = 0; i < n; ++i)
a[i] = lower_bound(b, b + b_tot, a[i]) - b;
}
LL dp[2][N];
int main() {
LL n, l, k;
scanf("%I64d%I64d%I64d", &n, &l, &k);
for(int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
lsh(a, n);
LL seg_num = l / n;
int leave = l % n;
if(leave) ++seg_num;
else leave = n;
LL ans = l % MOD;
for(int i = 0; i < n; ++i) {
++dp[0][a[i]];
}
int now = 1, pre = 0;
for(int i = 1; i < min(seg_num, k); ++i) {
dp[now][0] = 0;
for(int j = 1; j < b_tot; ++j) {
dp[pre][j] = (dp[pre][j] + dp[pre][j - 1]) % MOD;
dp[now][j] = 0;
}
for(int j = 0; j < n; ++j) {
dp[now][a[j]] = (dp[now][a[j]] + dp[pre][a[j]]) % MOD;
if(j < leave) {
ans = (ans + dp[pre][a[j]] * ((seg_num - i) % MOD)) % MOD;
} else {
ans = (ans + dp[pre][a[j]] * ((seg_num - i - 1) % MOD)) % MOD;
}
}
swap(pre, now);
}
if(ans < 0) ans += MOD;
cout<<ans<<endl;
return 0;
}