poj 1887 Testing the CATCHER(动态规划:LIS)
来源:互联网 发布:日本找工作知乎 编辑:程序博客网 时间:2024/06/03 11:01
类似求LIS(最长递增子序列)
从每个i开始遍历,对于大于i的所有j,取dp[j] = max(dp[i]+1, dp[j])
这道题的坑点就在于输出,以及只有一个有效数据时的处理
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#define MAXN 100010using namespace std;int a[MAXN], dp[MAXN];int main(void) { int T = 1, ans; while(scanf("%d", &a[0]) && a[0]!=-1) { int cnt = 1; while(scanf("%d", &a[cnt++])) { dp[cnt-1] = 1; if(a[cnt-1] == -1) break; } --cnt; ans = 0; dp[0] = 1; for(int i=0; i<cnt; ++i) { for(int j=i+1; j<cnt; ++j) { if(a[i] >= a[j]) { dp[j] = max(dp[i]+1, dp[j]); } } } for(int i=0; i<cnt; ++i) ans = max(ans, dp[i]); if(cnt == 2) ans = 1; printf("Test #%d:\n", T++); printf(" maximum possible interceptions: %d\n\n", ans); } return 0;}
0 0
- poj 1887 Testing the CATCHER(动态规划:LIS)
- POJ 1887 Testing the CATCHER(LIS)
- Poj 1887 Testing the CATCHER(LIS)
- poj-1887Testing the CATCHER(LIS变形)
- 动态规划(4)Testing the CATCHER 1887
- 动态规划【 Testing the CATCHER】
- POJ 1887 Testing the CATCHER 最长不下降序列(LIS)问题
- POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)
- POJ-1887-Testing the CATCHER-最长递减子序列-DP动态规划
- poj 1887 Testing the CATCHER
- poj 1887 Testing the CATCHER
- poj 1887 Testing the CATCHER
- Poj 1887 Testing the CATCHER
- poj 1887 Testing the CATCHER
- POJ 1887 Testing the CATCHER
- poj 1887 Testing the CATCHER
- POJ-1887-Testing the CATCHER
- poj 1887 Testing the CATCHER
- 硬件设计中电容电感磁珠总结
- jquery 和 js 的区别
- 深入探讨C++中的引用
- struts2结果类型
- MD5算法
- poj 1887 Testing the CATCHER(动态规划:LIS)
- Activity 的四种状态
- 软件测试-file fuzzing
- hibernate + spring 集成参考
- struts2拦截器
- struts2中的数据校验文件配置方法
- Java 并发编程之任务取消 (二)
- 个人总结
- IOS_改变UITextField placeHolder颜色、字体