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/problem/D
Description
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 109 + 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, k, n × k ≤ 106 and 1 ≤ l ≤ 1018).
The second line contains n space separated integers, a0, a1, ..., an - 1 (1 ≤ ai ≤ 109 for each 0 ≤ i ≤ n - 1).
Output
Sample Input
3 5 3
5 9 1
Sample Output
10
HINT
题意
给你n,l,k,然后就是告诉你b有l长度,其中是由a不停重复得到的
然后问你一共有多少个满足条件的序列存在
条件如下:
1.这个序列的长度大于等于1,小于等于k
2.这个序列在每一个块中只能选择一个数,并且都必须选择在连续的块中
3.这个序列是单调不降的
题解:
dp,由于n*k<=1e6,所以我们简单的推断是dp[n][k]的,表示第i个数长度为k的序列有多少个
其实这道题和分块差不多,在块外就用dp瞎转移
块内就暴力就好了……
只要把这个数据过了就好了
3 100 3
1 1 1
注意是upper_bound这个东西
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define maxn 1000005
#define mod 1000000007
int a[maxn];
int b[maxn];
long long l;
int k,n;
long long dp[maxn];
long long sum[maxn];
map<int,int> HH;
map<pair<int,int>,int> H;
int tot = ;
int get(int x,int y)
{
if(H[make_pair(x,y)])
return H[make_pair(x,y)];
H[make_pair(x,y)]=tot++;
return H[make_pair(x,y)];
}
int main()
{
scanf("%d%lld%d",&n,&l,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(a+,a++n);
for(int i=;i<=n;i++)
HH[a[i]] = i;
for(int i=;i<=n;i++)
dp[get(i,)]=;
for(int j=;j<=k;j++)
{
int tot = ;
for(int i=;i<=n;i++)
{
int kk = upper_bound(a+,a+n+,a[i])-(a+);
while(tot<=kk)
{
sum[j-] += dp[get(tot,j-)];
sum[j-] %= mod;
tot++;
}
dp[get(i,j)] = sum[j-];
}
}
for(int i=;i<=n;i++)
{
sum[k] += dp[get(i,k)];
sum[k] %= mod;
}
long long ans = ;
for(int i=;i<=k&&i<=l/n;i++)
{
ans += (long long)((l/n-i+)%mod)*sum[i];
ans %= mod;
}
if(l%n==)
{
cout<<ans<<endl;
return ;
}
for(int i=;i<=l%n;i++)
{
for(int j=;j<=k&&j<=(l/n+);j++)
{
ans+=dp[get(HH[b[i]],j)];
ans%=mod;
}
}
cout<<ans<<endl;
}
Codeforces Round #326 (Div. 2) D. Duff in Beach dp的更多相关文章
- Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数
B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...
- Codeforces Round #326 (Div. 2) A. Duff and Meat 水题
A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...
- Codeforces Round #326 (Div. 2) B Duff in Love 简单数论 姿势涨
B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #326 (Div. 1) - C. Duff in the Army 树上倍增算法
题意:一个n个点的数, m个人住在其中的某些点上, 每个人的标号1-m, 询问u-v 路径上标号前a个人,并输出标号,a < 10. 作法, 利用倍增, ID[j][i] 表示i到i的第2^j个 ...
- Codeforces Round #326 Div.1 C.Duff in the Army 树上倍增
题意概述: 给出一棵N个结点的树,然后有M个居民分散在这棵树的结点上(允许某个结点没有居民).现在给出一些询问形如u,v,a,定义k=min(x,a),其中x表示的是u->v路径上的居民数量.将 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting
B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...
- Codeforces Round #326 (Div. 2)-Duff and Meat
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
随机推荐
- Java中的面向接口编程
面向接口编程是很多软件架构设计理论都倡导的编程方式,学习Java自然少不了这一部分,下面是我在学习过程中整理出来的关于如何在Java中实现面向接口编程的知识.分享出来,有不对之处还请大家指正. 接口体 ...
- 多线程监控文件夹,FlieSystemWatcher,并使用共享函数
发表于: 2011-01-06 09:55:47 C# code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...
- MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
目录(?)[-] 二SQL语句映射文件2增删改查参数缓存 select insert updatedelete sql parameters 基本类型参数 Java实体类型参数 Map参数 多参数的实 ...
- 在stm32上移植wpa_supplicant(一)
wifi芯片为88w8686,已经写好了驱动,用的是SPI方式,接下来准备移植wpa_supplicant.参考的资料为一篇论文----<基于微控制器的WPA技术研究与应用>. wpa_s ...
- strcasecmp在VS2010中提示未定义标识符
分析: strcasecmp(*,*)是用来比较字符串,定义在string.h头文件中,但是在windows下即使添加string.h头文件,依然会报错. 解决: 添加 #if defined(_MS ...
- 常见设计模式的解析和实现(C++)之九—Decorator模式
作用:动态地给一个对象添加一些额外的职责.就增加功能来说,Decorator模式相比生成子类更为灵活. UML结构图: 抽象基类: 1) Component :定义一个对象接口,可以为这个接口动态地 ...
- 在DataTable 中增加一列
//在这里需要增加一个列. DataColumn column = dt.Columns.Add("行号", Type.GetType("S ...
- WCF启用Session
1 服务类添加ASPNETSESSION兼容标记 [System.ServiceModel.Activation.AspNetCompatibilityRequirements(Requirement ...
- bzoj 1025 [SCOI2009]游戏(置换群,DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1025 [题意] 给定n,问1..n在不同的置换下变回原序列需要的不同排数有多少种. [ ...
- htmlcss笔记--标签默认值样式重置css reset
1.<a>标签 有默认文字修饰:下划线, 去除:text-decoration:none; text-decoration属性值: none 默认.定义标准的文本. underline 定 ...