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, kn × 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

Print the answer modulo 1 000 000 007 in one line.

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<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define maxn 1000005
#define mod 1000000007
int a[maxn];
int b[maxn];
long long l;
int k,n;
long long dp[maxn];
long long sum[maxn];
map<int,int> HH;
map<pair<int,int>,int> H;
int tot = ;
int get(int x,int y)
{
if(H[make_pair(x,y)])
return H[make_pair(x,y)];
H[make_pair(x,y)]=tot++;
return H[make_pair(x,y)];
}
int main()
{
scanf("%d%lld%d",&n,&l,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(a+,a++n);
for(int i=;i<=n;i++)
HH[a[i]] = i;
for(int i=;i<=n;i++)
dp[get(i,)]=;
for(int j=;j<=k;j++)
{
int tot = ;
for(int i=;i<=n;i++)
{
int kk = upper_bound(a+,a+n+,a[i])-(a+);
while(tot<=kk)
{
sum[j-] += dp[get(tot,j-)];
sum[j-] %= mod;
tot++;
}
dp[get(i,j)] = sum[j-];
}
}
for(int i=;i<=n;i++)
{
sum[k] += dp[get(i,k)];
sum[k] %= mod;
}
long long ans = ;
for(int i=;i<=k&&i<=l/n;i++)
{
ans += (long long)((l/n-i+)%mod)*sum[i];
ans %= mod;
}
if(l%n==)
{
cout<<ans<<endl;
return ;
}
for(int i=;i<=l%n;i++)
{
for(int j=;j<=k&&j<=(l/n+);j++)
{
ans+=dp[get(HH[b[i]],j)];
ans%=mod;
}
}
cout<<ans<<endl;
}

最新文章

  1. 一台电脑上的git同时使用两个github账户
  2. c语言中在引用math库后,编译出现错误(.text+0x9c):对‘sqrt’未定义的引用的解决办法
  3. PHP入门介绍与环境配置
  4. JavaMail发送邮件时判断发送结果1.5.x
  5. 8.3 ContosoMVCWeb官方案例学习
  6. PAT (Basic Level) Practise:1005. 继续(3n+1)猜想
  7. Vim--写在开始
  8. Web颜色搭配 - 收集
  9. .net面试题大全(有答案)
  10. Linux下mysql的常用操作
  11. 托管C++、C++/CLI、CLR
  12. mysq数据库相关操作
  13. python多环境下虚拟环境的搭建和使用
  14. iOS代码块block使用
  15. Django--缓存设置
  16. Nginx 的 TCP 负载均衡介绍
  17. Linux 环境下使用g++编译C++
  18. makefile中&quot;:=&quot;,&quot;=&quot;,&quot;?=&quot;,&quot;+=&quot;
  19. CF603EPastoral Oddities
  20. 冬瓜头答疑:磁盘阵列内部FC-AL的性能问题

热门文章

  1. 【unity3D】鼠标控制camera的移动、放大(俯视浏览效果、LOL摄像机移动效果)
  2. RTMP协议详解(转)
  3. TCP/IP详解学习笔记(14)-TCP连接的未来和性能(未写完)
  4. validate.plugin.js 验证插件
  5. SQL SERVER 实现分组合并实现列数据拼接
  6. [Irving]字符串相似度-字符编辑距离算法(c#实现)
  7. 两段简单的JS代码防止SQL注入
  8. codevs1796-最小完全图
  9. 【原】Storm分布式RPC
  10. 数往知来C#之面向对象准备〈一〉