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 ...
随机推荐
- Html5上传插件封装
前段时间将flash的上传控件替换成使用纯js实现的,在此记录 1.创建标签 <div class="camera-area" style="display:inl ...
- React学习之redux
在阅读本文之前,希望大家对以下知识点能提前有所了解并且上好厕所(文章有点长): 状态提升的概念 react高阶组件(函数) es6基础 pure 组件(纯函数) Dumb 组件 React.js的co ...
- JAVA实现KNN分类
转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/51064307 http://www.llwjy.com/blogdetail/f ...
- C语言 结构体篇
结构体:是一种构造类型 它是由若干成员组成的 其中每一个成员都可以是一个基本数据类型或者又是一个构造类型 定义结构体变量后,系统就会为其自动分配内存 为了便于更大的程序便于修改和使用 常常将结构体类 ...
- 显存不够----ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[4096]
ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[4096] 类似问题 h ...
- 使用Docker开发NodeJs APP
英文版原文地址 这是两篇连载文章的第一篇,讲解了如何使用 Docker 替代 Vagrant 开发基于 Express 框架的NodeJs App的部分细节.不过,这次要增加点难度:我们要使用 con ...
- mysql解决中文乱码
mysql>use mydb; mysql>alter database mydb character set utf8;! 这种方法只对设置后重新创建的表有效,对已存在的表无效 des ...
- 02-cookie案例-显示用户上次访问网站的时间
package cookie; import java.io.IOException;import java.io.PrintWriter;import java.util.Date; import ...
- hdu 1068 Girls and Boys 二分图的最大匹配
题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...
- C#游戏开发高速新手教程Unity5.5教程
C#游戏开发高速新手教程Unity5.5教程 试读文档下载地址:http://pan.baidu.com/s/1slwBHoD C#是微软公布的高级程序设计语言.这门语言和C语言一样,已经成为了大学计 ...