codeforces 587B B. Duff in Beach(dp)
题目链接:
2 seconds
256 megabytes
standard input
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.
The first line of input contains three integers, n, l and k (1 ≤ n, k, n × 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).
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
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)的更多相关文章
- 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 ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
- [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)
[Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...
- codeforces Diagrams & Tableaux1 (状压DP)
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...
- Codeforces 467C George and Job(DP)
题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...
- Codeforces Beta Round #17 C. Balance DP
C. Balance 题目链接 http://codeforces.com/contest/17/problem/C 题面 Nick likes strings very much, he likes ...
- codeforces 258div2 A Game With Sticks(DP)
题目链接:http://codeforces.com/contest/451/problem/A 解题报告:有n跟红色的棍子横着放,m根蓝色的棍子竖着放,它们形成n*m个交点,两个人轮流在里面选择交点 ...
- codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...
随机推荐
- kettle转换之多线程
kettle转换之多线程 ETL项目中性能方面的考虑一般是最重要的.特别是所讨论的任务频繁运行,或一些列的任务必须在固定的时间内运行.本文重点介绍利用kettle转换的多线程特性.以优化其性能. ...
- rtmp 错误 Server error: call to function _checkbw failed
客户端使用rtmp协议与rtmp服务通信如遇到 Server error: call to function _checkbw failed错误 需要在服务端修改代码.如服务端使用的是CrtmpSer ...
- Qt on Android:将Qt调试信息输出到logcat中
版权全部 foruok .如需转载敬请注明出处(http://blog.csdn.net/foruok). 假设你在目标 Android 设备上执行了 Qt on Android 应用,你可能希望看到 ...
- Nginx绑定多个域名的方法
nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里. 一.每个域名一个 ...
- Uboot的串口下载文件命令:loads / loadb / loady
1. loads loads [ off ] 通过串口,下载S-Rec文件到off位置 loads命令可以通过串口线下载S-Record格式文件. 2. loadb loadb [ off ] [ b ...
- 必会必知git
git必会必知 1 前言 git前身是BitKeeper,但是他不是开源软件,不符合当时开源趋势,于是就会有了开源的git,git开发只用了十天时间.目前git是公司开发必不可少的一个工具,用于多 ...
- Java8中 Date和LocalDateTime的相互转换
一.在Java 8中将Date转换为LocalDateTime 方法1: 将Date转换为LocalDatetime,我们可以使用以下方法: 1.从日期获取ZonedDateTime并使用其方法toL ...
- android shareSDK 微博分享案例
android shareSDK 微博分享案例 ShareSDK APP_KEY 219b1121fc68 腾讯微博 key 801517904 secret bfba83ae253c8f38dabe ...
- Mybatis之入门Helloworld程序
本篇我们来实现一个Mybatis的Helloworld级别的一个示例程序. 一.搭建基本环境 1.基本开发环境搭建,这里选择: eclipse j2ee 版本,mysql 5.1 ,jdk 1.8,m ...
- HTML5+ 权限设置
API分模块封装调用了系统各种原生能力,而部分能力需要使用到Android的permissions,以下列出了各模块(或具体API)使用的的权限: -------------------------- ...