题目链接:

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. 修改Oracle SGA,以提高oracle性能

    在正常情况下,查询非常慢. 1.检查SGA大小,以DBA身份连接到oracle数据库,输入show sga. 2.如果SGA过小,请修改其大小 修改SGA必须保持的原则 1).sga_target不能 ...

  2. 转 FreeBSD通过PORTS安装软件的几个常用命令

    1.怎样找到我想安装的包路径:# cd /usr/ports# make search name=mysql2.仅仅下载源码包,而不安装:# cd /usr/ports/directory# make ...

  3. DML过程中记录错误日志

    当你插入几百万数据时,由于有几条脏数据而导致插入失败,是不是很恼火.10g R2之后有个新功能.将插入过程中失败的记录插入到还有一张表中. SQL> drop table test purge; ...

  4. HDU 4930 Fighting the Landlords(扯淡模拟题)

    Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...

  5. 基于togglepoolmember.pl编写F5设备控制模块

    为了方便利用python对F5设备进行操作,本文将togglepoolmember.pl对F5设备的控制写成了python模块,源代码例如以下: #!/usr/bin/python # -*- cod ...

  6. anaconda2下面安装opencv2.4.13.4完成----解决默认安装的问题----Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support. If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg

    转载自:http://blog.csdn.net/qingyanyichen/article/details/73550924 本人下载编译安装了opencv2.4.9,oppencv2.4.10,o ...

  7. 自定义 Android 钟表盘,这一篇就够了

    关于本文:本文原先在我的 CSDN 博客发布(由图片水印能发现),整理以往博客过程中,发现当时总结的很仔细,所以将其迁移到这里,希望对大家在自定义 View 方面,能有所帮助

  8. com.opensymphony.xwork2.ognl.OgnlValueStack - Error setting expression 'customer.applyRate' with value '[Ljava.lang.String;@7d3fae2c'

    出错的3个最可能的原因:我是第二种错误 1.action配置错误 <action name="doCreateMeetingInfo" class="meeting ...

  9. Intellij IDEA如何不显示参数提示

    刚安装了IDEA之后,调用方法的时候会提示方法中的参数,就像下面这样: 虽然IDEA也是好心,提示,但是劳资看着难受啊. 如果觉得不习惯,不想看参数名,可以用下图的方式取消.具体是:  setting ...

  10. 有一个投篮游戏。球场有p个篮筐,编号为0,1...,p-1。每个篮筐下有个袋子,每个袋子最多装一个篮球。有n个篮球,每个球编号xi 。规则是将数字为xi 的篮球投到xi 除p的余数为编号的袋里。若袋里已有篮球则球弹出游戏结束输出i,否则重复至所有球都投完。输出-1。问游戏最终的输出是什么?

    // ConsoleApplication5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<vector> ...