2015 CCPC C题(超时代码)
来源:互联网 发布:瑞珀网络机顶盒升级包 编辑:程序博客网 时间:2024/05/17 08:11
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
Actually, if you leak information with strict increasing value could accelerate making Cao Cao believe you. So Gai Huang decided to leak exact
Input
The first line of the input gives the number of test cases,
Each test case begins with two numbers
Output
For each test case, output one line containing Case #x: y
, where
The result is too large, and you need to output the result mod by
Sample input and output
23 21 2 33 23 2 1
Case #1: 3Case #2: 0
Hint
In the first cases, Gai Huang need to leak
Source
题目大意:给你一个长度为n的数列,问你有多少组长度为m的递增数列;
题目大意很简单,现场赛的时候定义错状态,没能做出来;
定义dp[i][j]表示长度为j,以第i个数结尾的递增序列的组数;
所以状态转移方程不就是if(a[i] > a[k] ) dp[i][j] += dp[k][j-1];
代码如下(不能够通过的):
#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;long long dp[1005][1005], s[1005];void test_case(){ int n,m; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) scanf("%d",&s[i]); memset(dp,0,sizeof(dp)); for(int i=1; i<=n; i++) { dp[i][1]=1; for(int j=1; j<=m; j++) for(int k=1; k<i; k++) { if(s[i] > s[k]) dp[i][j] += dp[k][j-1]; dp[i][j] %= 1000000007; } } long long ans = 0; for(int i=1; i<=n; i++) { ans += dp[i][m]; } printf("%lld\n",ans%1000000007);}int main(){ int t; scanf("%d",&t); for(int c=1; c<=t; c++) { printf("Case #%d: ",c); test_case(); } return 0;}这是n三方的代码,不能够过这题的,博主太弱了,不会优化;
据说要用树状数组求逆序对的思想优化一下,博主这两天正在学习树状数组:
先占坑,待补;
- 2015 CCPC C题(超时代码)
- CCPC 2015 A题
- 2015 CCPC D题
- 2015 CCPC C题 【树状数组优化dp】
- 2015南阳CCPC部分题目代码
- 2015 CCPC A题 【水题】
- 2015 CCPC H题 【DFS】
- 2015 CCPC L题 【水题】
- 2015南阳ccpc L题
- 2015南阳ccpc L题
- 2015CCPC湖南J题
- CCPC - k题(dp)
- 2015年CCPC D题 Pick The Sticks(DP)
- 2017 CCPC 秦皇岛 C
- 2015 CCPC G题 【DFS 暴力】
- 2015 南阳 CCPC hdu5547 Sudoku(DFS)
- HDU5547 Sudoku(深搜DFS)(2015CCPC)
- 2015CCPC南阳场 C - The Battle of Chibi
- 电源调试记录五
- recyclerview设置布局样式
- qt学习之QSting类型转换
- Wireless工具移植之wpa_supplicant
- 使用systemb过程
- 2015 CCPC C题(超时代码)
- 高级字符串查找
- hadoop入门笔记[一]
- 电源调试记录六
- C : stack memory, goto and “jump into scope of identifier with variably modified type”,
- 从n个元素的列表中查找最大值(C实现)
- HDU2203-亲和串-KMP模板题
- 在Mac电脑配置服务器,让别人访问
- Apache VirtualHost 虚拟主机 ProxyPass 反向代理 RewriteEngine url 重写