题目链接:

B. Duff in Beach

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 10^9 + 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 ≤ 10^6 and 1 ≤ l ≤ 10^18).

The second line contains n space separated integers, a0, a1, ..., an - 1 (1 ≤ ai ≤ 10^9 for each 0 ≤ i ≤ n - 1).

Output

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

Examples
input
3 5 3
5 9 1
output
10
input
5 10 3
1 2 3 4 5
output
25
Note

In the first sample case, . So all such sequences are:  and .

题意:

给一个数组a,然后循环产生长为l的数组,问满足题目给的条件的子序列有多少个;满足的条件为要求不单调递减,而且最长为k,且每相邻的两个来自相邻的段;

思路:

dp[i][j]表示以第i个数结尾的长为j的子序列的个数;转移方程为dp[i][j]=∑dp[x][j-1](满足a[x]<=a[i]所有x);由于n,k的范围太大,所以可以取一维的数组;

dp[i]=∑dp[x](a[x]<=a[i])每层j求完就把答案更新到ans中,还有一个难点就是l%n>0的时候,有前边记录的dp[i]可以把l%n部分求出来;

AC代码:

/*
2014300227 587B - 19 GNU C++11 Accepted 311 ms 33484 KB
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+;
int n,k,b[N],vis[N];
ll l,dp[N],temp[N];
const ll mod=1e9+;
struct node
{
friend bool operator< (node x,node y)
{
if(x.a==y.a)return x.pos<y.pos;
return x.a<y.a;
}
int a,pos;
};
node po[N];
int main()
{ cin>>n>>l>>k;
for(int i=;i<n;i++)
{
scanf("%d",&po[i].a);
po[i].pos=i;
}
sort(po,po+n);
po[n].a=po[n-].a+;
for(int i=n-;i>=;i--)
{
if(po[i].a==po[i+].a)vis[i]=vis[i+];//vis[i]记录与a[i]相等的最后一个数的位置;
else vis[i]=i;
b[po[i].pos]=i;//把位置还原
}
for(int i=;i<n;i++)
{
dp[i]=;
}
ll ans=l,sum,fn=(ll)n;
ans%=mod;
for(int i=;i<=k;i++)
{
temp[]=dp[];
for(int j=;j<n;j++)
{
temp[j]=temp[j-]+dp[j];//temp[j]用来过渡;
temp[j]%=mod;
}
sum=;
for(int j=;j<n;j++)
{
dp[j]=temp[vis[j]];
sum+=dp[j];
sum%=mod;
}
if(l%fn==)
{
if(i<=l/fn)
{
ans+=((l/fn-i+)%mod)*sum;
ans%=mod;
}
}
else
{
if(i<=l/fn)
{
ans+=((l/fn-i+)%mod)*sum;
ans%=mod;
sum=;
for(int j=;j<l%fn;j++)
{
sum+=dp[b[j]];
sum%=mod;
}
ans+=sum;
ans%=mod;
}
else if(i==l/fn+)
{
sum=;
for(int j=;j<l%fn;j++)
{
sum+=dp[b[j]];
sum%=mod;
}
ans+=sum;
ans%=mod;
}
}
}
cout<<ans%mod<<"\n";
return ;
}

codeforces 587B B. Duff in Beach(dp)的更多相关文章

  1. Codeforces Round #326 (Div. 2) D. Duff in Beach dp

    D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  2. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  3. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

  4. [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)

    [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...

  5. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  6. Codeforces 467C George and Job(DP)

    题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...

  7. Codeforces Beta Round #17 C. Balance DP

    C. Balance 题目链接 http://codeforces.com/contest/17/problem/C 题面 Nick likes strings very much, he likes ...

  8. codeforces 258div2 A Game With Sticks(DP)

    题目链接:http://codeforces.com/contest/451/problem/A 解题报告:有n跟红色的棍子横着放,m根蓝色的棍子竖着放,它们形成n*m个交点,两个人轮流在里面选择交点 ...

  9. codeforces 597C (树状数组+DP)

    题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...

随机推荐

  1. iOS常用的加密方式

    MD5 iOS代码加密 创建MD5类,代码如下 #import <Foundation/Foundation.h> @interface CJMD5 : NSObject +(NSStri ...

  2. JVM中垃圾收集选项

    最初并发垃圾收集被引入的时候,激活并发垃圾收集的命令选项是: -XX:+UseParallelGC 增强的并行收集和Java 6一起发布,通过一个新的命令行选项: -XX:+UseParallelOl ...

  3. 已知某公司总人数为W,平均年龄为Y岁(每年3月末计算,同时每年3月初入职新人),假设每年离职率为x,x>0&&x<1,每年保持所有员工总数不变进行招聘,新员工平均年龄21岁。 从今年3月末开始,请实现一个算法,可以计算出第N年后公司员工的平均年龄。(最后结果向上取整)。

    // ConsoleApplication12.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" // ConsoleApplication1 ...

  4. 字符串转化成十六进制输出StrToHex(Delphi版、C#版)

    //注意:Delphi2010以下版本默认的字符编码是ANSI,VS2010的默认编码是UTF-8,delphi版字符串事先须经过AnsiToUtf8()转码才能跟C#版得到的十六进制字符串显示结果一 ...

  5. 新手学习JSP+Servlet笔记一

    作为一个新手,初次接触jsp,servlet,习惯了后台的开发,前台的知识一窍不通,利用闲暇时间,给自己补补,从MyEclipse开始. 安装好MyEclipse之后,没有安装程序的可以下载 http ...

  6. Java源代码之LinkedHashMap

    Java源代码之LinkedHashMap 转载请注明出处:http://blog.csdn.net/itismelzp/article/details/50554412 一.LinkedHashMa ...

  7. linux下压缩成zip文件解压zip文件

    linux  zip命令的基本用法是: zip [参数] [打包后的文件名] [打包的目录路径] linux  zip命令参数列表: -a     将文件转成ASCII模式 -F     尝试修复损坏 ...

  8. oracle 存储过程(1)

    说明 创建一个存储过程与编写一个普通的PL/SQL程序快有很多相似地方,比如:包括生命部分,执行部分和异常部分.但是两者之间实现细节还是有很多差别的,比如:创建存储过程需要使用procedure关键字 ...

  9. H2 database 应用

    以前对内存表的引用一直采用sqllite,由于sqllite对字段的局限性无法满足需要.后来对h2 有了一定青睐做了下应用.下面对h2进行介绍. 1. H2数据库引擎 H2数据库由Java编写的,它可 ...

  10. iOS开发 两个内存错误的一般处理方法

    本文转载至 http://blog.sina.com.cn/s/blog_a843a8850101dxlj.html 由于iOS5.0之前没有自动应用计数机制,也没有Java那样的垃圾回收功能.我们都 ...