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的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
随机推荐
- JavaScript--事件模型(转)
在各种浏览器中存在三种事件模型:原始事件模型( original event model),DOM2事件模型,IE事件模型.其中原始的事件模型被所有浏览器所支持,而DOM2中所定义的事件模型目前被除了 ...
- [Everyday Mathematics]20150105
设 $f\in C^1(a,b)$ 适合 $$\bex \lim_{x\to a^+}f(x)=+\infty,\quad \lim_{x\to b^-}f(x)=-\infty, \eex$$ 并且 ...
- logback.xml配置
一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文 ...
- E asy Boo t 6.51 启动易 制作启动光盘的软件(附注册码)
内建ISO文件生成器,可直接生成可启动ISO文件,并支持N合1优化. -------中文版注册码------- 用户名:中华人民共和国 注册码:2898-5448-5603-BB2D -------英 ...
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(6)
创建一个新文档(Creating a new document) 现在我们将尝试索引一些文档.对于我们的示例,让我们想象我们正在为我们的博客建立某种CMS.实体之一是博客的文章.使用JSON记法,在以 ...
- 使用DDMS测试安卓手机APP的性能(android)
安装/配置: 通过另外一个工具也可以测试手机客户端APP的性能,这就是android开发包中的DDMS工具(Dalvik Debug Monitor Service),先来说一下android开发包的 ...
- 获取本机外网IP的方式笔记
1.IP138 网址:http://www.ip138.com/: 分离出的快速查询地址:http://20140507.ip138.com/ic.asp(2014年8月9日有效) 个人经验:百度搜索 ...
- CodeForce---Educational Codeforces Round 3 Load Balancing 正题
看到这题是我的想法就是肯定跟平均值有关但是接下来就不知道怎么做了 看完大神的正解数之后,原来发现是这么简单,但是就是不知道为啥一定是平均值和平均值加1,而不是平均值和平均值减1: 好啦下面就贴出大神的 ...
- 【和我一起学python吧】python的一些推荐
看到未名的几篇帖子 使我想起了和python的一些经历,于是写了一篇咚咚. 1 书籍: python的syntax足够简单,semantics也不复杂,不怎么会使人混乱,一般来说看自带的文档足够可以学 ...
- Javascript原理
1.javascript创建对象 创建新对象有两种不同的方法: 定义并创建对象的实例 person=new Object(); person.firstname="Bill"; p ...