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 ...
随机推荐
- Ruby之Rspec的报错解决
#enconding:utf-8 require 'selenium-webdriver' require 'rspec' describe "baidu main page" d ...
- Web前端学习攻略
HTML+CSS: HTML进阶.CSS进阶.div+css布局.HTML+css整站开发. JavaScript基础: Js基础教程.js内置对象常用方法.常见DOM树操作大全.ECMAscript ...
- 笔记本中LVDS屏与eDP屏的比较
LVDS,即Low Voltage Differential Signaling,是一种低压差分信号技术接口.它是美国NS公司(美国国家半导体公司)为克服以TTL电平方式传输宽带高码率数据时功耗大.E ...
- Linux系统下授权MySQL账户访问指定数据库和数据库操作
Linux系统下授权MySQL账户访问指定数据库 需求: 1.在MySQL中创建数据库mydata 2.新建MySQL账户admin密码123456 3.赋予账户admin对数据库mydata具有完全 ...
- Hibernate学习三----------session详解
© 版权声明:本文为博主原创文章,转载请注明出处 如何获取session对象 1. openSession 2. getCurrentSession - 如果使用getCurrentSession需要 ...
- scrapy之Logging使用
#coding:utf-8 __author__ = 'similarface' ###################### ##Logging的使用 ###################### ...
- Rate Monotonic Scheduling algorithm
这篇文章写得不错 http://barrgroup.com/embedded-systems/How-To/RMA-Rate-Monotonic-Algorithm 另外rtems的官方文档也有类似说 ...
- 转:MSN君最后的十个瞬间
五年前我用过MSN五年.在一家ERP公司当程序猿的时候我甚至在业余时间做过一款MSN订餐机器人. 转完这篇文章.就是真正跟MSN的bye bye了. 转自:www.gogo.cn 今天是一个普通的周五 ...
- 02 redis通用命令操作
set hi hello 设置值 get hi 获取值 keys * 查询出所有的key memcached 不能查询出所有的key keys *h 模糊查找key keys h[ie] 模糊查找 k ...
- PowerBuilder -- 指定重复的列不显示