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的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
随机推荐
- Oracle 11g AMM与ASMM切换
现在的Oracle正在往智能化方向发展.如果我们现在找一些8i/9i时代的Oracle书籍,怎么样配置合适的数据库各内存池大小是非常重要的话题.但是进入10g之后,自动内存池调节成为一个重要Oracl ...
- 锋利的jQuery读书笔记---选择器
前段时间入手了锋利的jQuery(第二版),想着加强下自己的js能力,可前段时间一只在熟悉Spring和Hibernate.最近抽时间开始读这本书了,随便也做了些记录. 读书的过程是边看边代码测试,所 ...
- Android中不混淆类中函数
情况一:混淆不同的函数aTest.bTest -keep class com.zony.Test { void aTest(byte[], int, int); void bTest(String, ...
- 擦亮自己的眼睛去看SQLServer之简单Select(转)
摘要:这篇文章主要和大家讨论几乎所有人都熟悉,但不少人又陌生的一条select语句. 这篇文章主要和大家讨论几乎所有人都熟悉,但不少人又陌生的一条select语句.不知道大家有没有想过到底是什么东西让 ...
- Alibaba
题意: 有n个东西在一条路上,已知他们的位置,和能获得他们的最后期限,求能获得n个东西的最小总时间. 分析: 想到了求”未来费用问题", dp[i][j][k]表示获得区间长i起点为j的所有 ...
- 【剑指offer 面试题14】调整数组顺序使奇数位于偶数前面
思路: 头尾指针,向中间遍历,依据条件交换元素. #include <iostream> using namespace std; void reOrder(int *pData, uns ...
- 软件测试技术(五)——Software Review
本周的测试课上进行了一次同行评审的演练,大家讨论的很热烈,不过我也发现了一些不太理解的过程,如如何进行计划活动,走读.技术评审.正规检视是基于什么目的,并应该在何时进行.我做了一下详细的研究. 首先, ...
- 获取json中字段,判断是否有想要的key
if(json.containsKey("key")){ String refundSid = json.getString("key"); } 如果也要判断v ...
- 【C++11】 lambda表达式
i.e.int x = 10;int y = 20;int z = [&]{ x = x * x; y = y * y; return x + y;}(); 上面z后面以[]开头的为一个lam ...
- 感知器Perceptron
Perceptron: 1.一种基于监督的线性分类器,其特点是:1)模型简单,具有很少的学习参数:2)具有可视性,一条直线即可划分:3)基于人工神经网络的原理. 其结构图为: 2.学习的关键技术: ...