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. mysql 如何创建一个简单的存储过程

    1 用mysql客户端登入2 选择数据库 mysql>use test3 查询当前数据库有哪些存储过程 mysql>show procedure status where Db='test ...

  2. 外文翻译 《How we decide》多巴胺的预言 第三节

    这是第二章的最后一节. 书的导言 本章第一节 本章第二节 本节阅读感言:自我批评是自我提升的妙方. 多巴胺是我们感情的源泉.多巴胺相关的神经系统在不断的记录着我们主观意识没有注意到的一个个模式,将它们 ...

  3. Python调用Java代码部署及初步使用

    Python调用Java代码部署: jpype下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype 下载的时候需要使用Chrome浏览器进行下载 ...

  4. Tomcat配置Oracle数据源

    开发环境:Eclipse luna.tomcat 7.Oracle 配置Oracle datasource步骤 第一步:打开tomcat目录下的 context.xml 文件,添加 Resource ...

  5. layer设置弹出全屏

    //弹出即全屏 var index = layer.open({ type: , content: 'http://www.layui.com', area: ['300px', '195px'], ...

  6. varchar2(100 char)是什么意思

    最佳答案   varchar2(100 char)最长可以插入100个任意字符而varchar2(100)最长可以插入100个英文字符

  7. (转)为Spring集成的Hibernate配置二级缓存

    http://blog.csdn.net/yerenyuan_pku/article/details/52896195 前面我们已经集成了Spring4.2.5+Hibernate4.3.11+Str ...

  8. droplang - 删除一种 PostgreSQL 过程语言

    SYNOPSIS droplang [ connection-option...] langname [ dbname] droplang [ connection-option...] --list ...

  9. vue 模块 props

    inbody.vue <template> <div> <Breadcrumb :style="{margin: '24px 0'}"> < ...

  10. Web前端技术体系大全搜索

    一.前端技术框架 1.Vue.js 官网:https://cn.vuejs.org/ Vue CLI:https://cli.vuejs.org/ 菜鸟教程:http://www.runoob.com ...