CDOJ 1217 The Battle of Chibi
The Battle of Chibi
Time Limit: 6000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Cao Cao made up a big army and was going to invade the whole South China. Yu Zhou was worried about it. He thought the only way to beat Cao Cao is to have a spy in Cao Cao's army. But all generals and soldiers of Cao Cao were loyal, it's impossible to convince any of them to betray Cao Cao.
So there is only one way left for Yu Zhou, send someone to fake surrender Cao Cao. Gai Huang was selected for this important mission. However, Cao Cao was not easy to believe others, so Gai Huang must leak some important information to Cao Cao before surrendering.
Yu Zhou discussed with Gai Huang and worked out N information to be leaked, in happening order. Each of the information was estimated to has ai value in Cao Cao's opinion.
Actually, if you leak information with strict increasing value could accelerate making Cao Cao believe you. So Gai Huang decided to leak exact M information with strict increasing value in happening order. In other words, Gai Huang will not change the order of the N information and just select M of them. Find out how many ways Gai Huang could do this.
Input
The first line of the input gives the number of test cases, T(1≤100). T test cases follow.
Each test case begins with two numbers N(1≤N≤103) and M(1≤M≤N), indicating the number of information and number of information Gai Huang will select. Then N numbers in a line, the ith number ai(1≤ai≤109) indicates the value in Cao Cao's opinion of the ith information in happening order.
Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the ways Gai Huang can select the information.
The result is too large, and you need to output the result mod by 1000000007(109+7).
Sample input and output
Sample Input | Sample Output |
---|---|
2 |
Case #1: 3 |
Hint
In the first cases, Gai Huang need to leak 2 information out of 3. He could leak any 2 information as all the information value are in increasing order. In the second cases, Gai Huang has no choice as selecting any 2 information is not in increasing order.
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int mod = ;
int c[maxn][maxn],a[maxn],b[maxn];
int sum(int i,int j,int ret = ) {
while(j > ) {
ret = (ret + c[i][j])%mod;
j -= j&-j;
}
return ret;
}
void add(int i,int j,int val) {
while(j < maxn) {
c[i][j] = (c[i][j] + val)%mod;
j += j&-j;
}
}
int main() {
int kase,n,m,cs = ;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
for(int i = ; i <= n; ++i) {
scanf("%d",a + i);
b[i-] = a[i];
}
memset(c,,sizeof c);
sort(b, b + n);
int cnt = unique(b,b + n) - b;
for(int i = ; i <= n; ++i)
a[i] = lower_bound(b,b + cnt,a[i]) - b + ;
for(int i = ; i <= n; ++i) {
add(,a[i],);
for(int j = ; j <= m; ++j) {
int t = sum(j-,a[i]-);
if(!t) break;
add(j,a[i],t);
}
}
printf("Case #%d: %d\n",cs++,sum(m,n+)%mod);
}
return ;
}
CDOJ 1217 The Battle of Chibi的更多相关文章
- uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...
- ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) = ...
- DP+BIT(优化复杂度) UESTC 1217 The Battle of Chibi
题目传送门 题意:问n长度的序列,找出长度m的上升子序列的方案数. 分析:这个问题就是问:dp[i][j] = sum (dp[i-1][k]) (1 <= k <= n, a[k] &l ...
- UESTC 1217 The Battle of Chibi
dp+树状数组优化. dp[i][j]表示以a[i]结尾,最长上升序列长度为j的方案数.dp[i][j]=sum{dp[k][j-1]} 其中k<i&&a[k]<a[i]. ...
- The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- 2015南阳CCPC C - The Battle of Chibi DP
C - The Battle of Chibi Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Cao Cao made up a ...
- hdu5542 The Battle of Chibi【树状数组】【离散化】
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- HDU - 5542 The Battle of Chibi(LIS+树状数组优化)
The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...
- 2015南阳CCPC C - The Battle of Chibi DP树状数组优化
C - The Battle of Chibi Description Cao Cao made up a big army and was going to invade the whole Sou ...
随机推荐
- Zernike矩之图像重建(附源码)
源码下载 参考: [1] Teague M R. Image analysis via the general theory of moments[J]. JOSA, 1980, 70(8): 920 ...
- 转 做了两款数据库监控工具(mysql and nosql),打算在近期开源
http://www.cnblogs.com/leefreeman/p/7297549.html 监控指标:https://www.linuxidc.com/Linux/2015-08/122009. ...
- c8051单片机注意事项:
一定要注意交叉开关问题:外设要想正确分配到指定引脚,一定要用配置工具确定分配到指定引脚:如果手动分配一定要仔细验证.这方面有个深刻的教训. 有个项目用c8051f020,用到2个串口,硬件已经确定好了 ...
- 前端编辑神器---sublime text2
个人印象 之前一直在用dreamweaver,但是由于软件太大,加载速度慢,所以sublime text2作为一款跨平台的编辑器,它的优势就展现出来了,它本身小巧,支持代码高亮,语法提示,自动完成,自 ...
- iOS面试题之内存管理
本文围绕内存管理的几种方法展开叙述. 1.内存管理是什么? 内存管理,就是对内存资源进行优化. 2.内存管理的三种方法? Objective-C的内存管理主要有三种方式ARC(自动内存计数).MRC( ...
- a=a+b与a+=b的区别
在一次工作中身边的一位资深的同事突然问了个a=a+b与a+=b有什么区别 此时有点尴尬了 不知道是真的不知道咧还是别有用意....今天抽点时间针对此问题做个小总结 一.性能方面 a=a+b是加法运算 ...
- 在docker容器中运行hello world!
在docker容器中运行hello world! docker容器可以理解为在沙盒中运行的进程.这个沙盒包含了该进程运行所必须的资源,包括文件系统.系统类库.shell 环境等等.但这个沙盒默认是不会 ...
- webapi之fiddler头设置
Host: localhost:16648Connection: keep-aliveContent-Length: 36Accept: application/json, text/javascri ...
- 系统设计摘录CAP
系统架构设计理论与原则 这里主要介绍几种常见的架构设计理论和原则,常见于大中型互联系统架构设计. (一).CAP理论 1.什么是CAP 所谓CAP,即一致性(Consistency).可用性(Avai ...
- IDEA一些设置
1. 设置字体为Consolas,Size:16, Line spacing: 1.1 2. 设置智能提示大小写不敏感 在设置中搜索sense, 找到配置节点 Editor->General-& ...