http://codeforces.com/contest/588/problem/D

感觉吧,这道题让我做,我应该是不会做的。。。

题目大意:给出n,L,K。表示数组的长度为n,数组b的长度为L,定义数组b[i]=a[i%n]。然后数组b的最长的lis为k,问能有几组<=k的lis

条件如下:

①序列长度>=1并且<=k

②序列在每一块长度为n的数组中只能选择一个数,且选择的必须是连续的块

③序列是不严格的单调递增

思路:主要是看这个人的http://m.blog.csdn.net/article/details?id=50589276

大致思路就是:定义dp[K][N](用dp[i][j]描述),表示目前lis的最长长度为i,到第j个数的时候lis总共有几个。然后求出lis以后再利用lis得到答案即可。

代码

//看看会不会爆int! 或者绝对值问题。
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ALL(a) a.begin(), a.end()
const int maxn = 1e6 + ;
const LL mod = 1e9 + ;
int n, K;
LL l;
pair<int, int> a[maxn]; int main(){
scanf("%d%lld%d", &n, &l, &K);
for (int i = ; i < n; i++){
int u;
scanf("%d", &u);
a[i] = mk(u, i);
}
sort(a, a + n);
vector<vector<int> > dp(K, vector<int>(n));
for (int i = ; i < n; i++) dp[][i] = ;
for (int i = ; i < K; i++){
int sum = ;
///dp[i][j]表示目前长度为i,在位置j之前的所有的lis的和
///首先,只以i和k转移,找到在一个周期内的
for (int j = , k = ; j < n; j++){
while (k < n && a[k].first <= a[j].first) {
sum = (sum + dp[i - ][k++]) % mod;
}
dp[i][j] = sum;
}
}
/*
for (int i = 0; i < K; i++){
for (int j = 0; j < n; j++){
printf("%d ", dp[i][j]);
}
printf("\n");
}
*/
LL ans = ;
for (int i = ; i < K; i++){
for (int j = ; j < n; j++){
///有l/n段长,后面的这个条件表示最后一个周期能否取到
LL cnt = l / n + (a[j].second < l % n);
if (cnt - i > ){///这里表明块,一共有cnt个,能满足这个长度
ans += (cnt - i) % mod * dp[i][j] % mod;
ans %= mod; }
}
}
printf("%lld\n", ans);
return ;
}

很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp的更多相关文章

  1. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  2. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  3. Codeforces Round #303 (Div. 2) C dp 贪心

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #235 (Div. 2) D (dp)

    以为是组合,后来看着像数位dp,又不知道怎么让它不重复用..然后就没思路 了. 其实状压就可以了 状压是可以确定一个数的使用顺序的 利用01也可以确定所有的数的使用以及不重复 dp[i+1<&l ...

  5. 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 ...

  6. 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E

    http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...

  7. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  8. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

  9. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

随机推荐

  1. Learning BSD.sys/queue.h

    This file includes 4 data-structures.. Insteresting because they are written in 1994.. to make it ea ...

  2. C#获取键盘和鼠标操作的时间的类

    /// /// 创建结构体用于返回捕获时间 /// [StructLayout(LayoutKind.Sequential)] struct LASTINPUTINFO { /// /// 设置结构体 ...

  3. OC工程调用Swift方法

    1.建一个OC工程命名为SwiftOC.如图所示: 2.新建一个swfit文件命名为Test.swift,会弹出提示,选择Create Bridging Header建立桥接文件,系统会建立“工程名- ...

  4. Windows server 2008搭建php运行环境

    下载php组件包 首先到http://windows.php.net/download/下载你需要的php版本,这里我下载的是php5.3. 下面解压php组件 包到磁盘上. 安装Microsoft ...

  5. Codeforces Round #364 (Div. 2) C.They Are Everywhere

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. Underscore.js 的模板功能介绍与应用

    Underscore是一个非常实用的JavaScript库,提供许多编程时需要的功能的支持,他在不扩展任何JavaScript的原生对象的情况下提供很多实用的功能,需要了解的朋友可以详细参考下   U ...

  7. As3.0 类的【枚举】

    As3.0 类的枚举   “枚举”是您创建的一些自定义数据类型,用于封装一小组值.ActionScript 3.0 并不支持具体的枚举工具,这与 C++ 使用 enum 关键字或 Java 使用 En ...

  8. LinuxIP地址、网卡相关、克隆、VM

    改IP地址(#setup) 1.输入vi /etc/sysconfig/network-scripts/ifcfg-eth0 2.里面的内容修改为 DEVICE=eth0HWADDR=FC:4D:D4 ...

  9. 使用SQL Server Management Studio 创建作业备份数据库

    在项目中,经常需要备份数据库,如果能做到只需点个按钮(“开始备份数据库”按钮),然后什么都不管,数据库就自动备份好了,或者服务器上的数据库隔一段时间自动备份一次,那该多好啊. Sql server 的 ...

  10. TexturePacker license Key免费获取方式

    TexturePacker是一款功能非常强大的图片制作工具.是一款付费软件,但是TexturePacker的作者Andreas Löw先生也给出获得免费key 的方法...大家可以到这个网站去申请 h ...