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 ;
}

最新文章

  1. centos mysql开启远程访问
  2. PHP获取POST数据的几种方法汇总
  3. [翻译]Bob大叔:反思极限编程
  4. Fast 迅捷网络 无线路由器FW323的功能设置
  5. ios框架中UIResponder的职责链设计模式应用
  6. yaffs文件系统
  7. (转)Eclipse “cannot be resolved to a type” error
  8. http协议本身能获取客户端Mac地址问题
  9. Java中传参的值传递和引用传递问题(转)
  10. MySQL 常用字段类型,介绍及其建表使用方法经验分享
  11. Linux PCI网卡驱动的详细分析
  12. [Spring面试] 问题整理
  13. 201521123097《Java程序设计》第五周学习总结
  14. Android下资源使用的方式-android学习之旅(五十三)
  15. C语言在linux内核中do while(0)妙用之法
  16. JS基础-第5天
  17. VMware对虚拟机快照进行克隆
  18. 在mmdetection中跑通MaskRCNN
  19. java中判断是否是一个无用的类
  20. PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/php/CreateDB.php on line 5

热门文章

  1. Cake slicing UVA - 1629
  2. 【转载】(0, eval)(‘this’)
  3. Spring Boot整合Spring Batch
  4. sed.exe 在bat中使用时,需要另外起一个文件
  5. 【HEVC帧间预测论文】P1.9 Coding Tree Depth Estimation for Complexity Reduction of HEVC
  6. 第16周翻译:SQL Server中的事务日志管理,级别3:事务日志、备份和恢复
  7. Python 学习日志9月21日
  8. TensorFlow低阶API(四)—— 图和会话
  9. iview table 已选项的数据 this.$refs.tables.$refs.tablesMain.getSelection()
  10. easyui前端框架01