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
3 2
1 2 3
3 2
3 2 1
Case #1: 3
Case #2: 0

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

The 2015 China Collegiate Programming Contest
 
解题:求长度为某个值得最长严格上升子序列的个数
数值数组优化dp
dp[i][j]表示以i结尾,长度为j的lis个数,可以得出转移方程是
\[dp[i][j] = \sum_{k < i,a[k] < a[i]}dp[k][j-1]\]
我们c[i][j]表示长度为i的,对应的方案数的树状数组
 #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的更多相关文章

  1. uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...

  2. ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) =  ...

  3. DP+BIT(优化复杂度) UESTC 1217 The Battle of Chibi

    题目传送门 题意:问n长度的序列,找出长度m的上升子序列的方案数. 分析:这个问题就是问:dp[i][j] = sum (dp[i-1][k]) (1 <= k <= n, a[k] &l ...

  4. 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]. ...

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

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

  7. hdu5542 The Battle of Chibi【树状数组】【离散化】

    The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

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

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

随机推荐

  1. 152 Maximum Product Subarray 乘积最大子序列

    找出一个序列中乘积最大的连续子序列(该序列至少包含一个数).例如, 给定序列 [2,3,-2,4],其中乘积最大的子序列为 [2,3] 其乘积为 6.详见:https://leetcode.com/p ...

  2. 2018微软实习笔试一道dp题目总结

    题意大概是说在一维数轴上起点和终点的距离是d,现在我们要从起点走到终点.每走一个单位长度消耗一个单位能量,初始时有K单位能量.同时在起点和终点之间分布一些加油站a1,a2,...an,给你加油站数量. ...

  3. TabLayout.Tab(自定义)点击事件

    TabLayout是官方design包中的一个布局控件,这里不介绍它的基本使用,只是解决Tab(自定义)点击事件. //获取Tab的数量 Int tabCount = tabLayout.getTab ...

  4. Android Studio 中文件查询方法总结

    搜索单词 Windows: Ctrl + F Mac   : Cmd + F 会在当前激活的文件上查询输入的关键字,以高亮显示 跳转行 Windows: Ctrl + L Mac   : Cmd + ...

  5. mybatis+oracle 完成插入数据库,并将主键返回的注意事项

    mybatis+oracle 完成插入数据库,并将主键返回的注意事项一条插入语句就踩了不少的坑,首先我的建表语句是: create table t_openapi_batch_info( BATCH_ ...

  6. DELETE - 删除一个表中的行

    SYNOPSIS DELETE FROM [ ONLY ] table [ WHERE condition ] DESCRIPTION 描述 DELETE 从指明的表里删除满足 WHERE 子句的行. ...

  7. vscode vue template 下 style 的样式自动提示 #bug 这个搞完vue语法esLint就又不好使了,ERR

    网上都是 "*.vue": "vue",改成"*.vue": "html" 就ok了   "files.ass ...

  8. matlab 随笔

    <<matlab高级编程技巧与应用:45个案例分析>> 一. 重新认识向量化编程 1.向量化编程与循环的比较 2.预分配内存更好 3.matlab中是列优先 4.归一化 数据归 ...

  9. 安卓adb在拨号键盘上输入井号(#)

    安卓系统下由于#号是属于内定字符,需要转义为%23第一种方式:adb shell service call phone 1 s16 "%23"第二种方式:adb shell am ...

  10. ORA-03113: end-of-file on & ORA-07445

    --------------ORA-03113: end-of-file on-------------- SQL> show parameter background_dump; NAME T ...