POJ 1887 Testing the CATCHER(最长非升子序列)
来源:互联网 发布:善待网络 编辑:程序博客网 时间:2024/06/10 19:38
题目比较长但是方法非常简单,就是求最长非升子序列。直接上代码。。。。
代码:
#include<iostream>#include<algorithm>using namespace std;int dp[5000];int num[5000];const int inf = 0x3f3f3f3f;int main() { int temp, Case = 0; int index = 0; while (cin >> temp, temp != -1) { num[index++] = temp; while (cin >> temp, temp != -1) { num[index++] = temp; } memset(dp, 0, sizeof(dp)); int top = 0; dp[top] = inf; for (int i = 0; i < index; ++i) { if (dp[top] >= num[i]) { dp[++top] = num[i]; } else { int low = 1, high = top; while (low <= high) { int mid = (low + high) >> 1; if (dp[mid] > num[i]) { low = mid + 1; } else { high = mid - 1; } } dp[low] = num[i]; } } cout << "Test #" << ++Case << ":" << endl; cout << " maximum possible interceptions: " << top << endl; cout << endl; index = 0; }}
#include<iostream>#include<algorithm>using namespace std;int dp[5000];int num[5000];const int inf = 0x3f3f3f3f;int main() { int temp, Case = 0; int index = 0; while (cin >> temp, temp != -1) { num[index++] = temp; while (cin >> temp, temp != -1) { num[index++] = temp; } for (int i = 0; i<index; i++) { dp[i] = 1; for (int j = 0; j<i; j++) { if (num[j] >= num[i]) dp[i] = max(dp[i], dp[j] + 1); } } int maxv = 0; for (int i = 0; i<index; i++) { if (dp[i]>maxv) maxv = dp[i]; } cout << "Test #" << ++Case <<":"<< endl; cout << " maximum possible interceptions: " << maxv << endl; cout << endl; index = 0; }}
0 0
- 【最长非升子序列】北大 POJ 1887 Testing the CATCHER
- POJ 1887 Testing the CATCHER(最长非升子序列)
- poj 1887Testing the CATCHER(最长下降子序列)
- poj 1887 Testing the CATCHER(最长递增子序列)
- poj 1887 Testing the CATCHER 最长不升子序列
- Testing the CATCHER - POJ 1887 最长递减子序列
- POJ 1887 Testing the CATCHER(最长递减子序列)
- POJ 1887-Testing the CATCHER(dp_最长下降子序列)
- POJ 1887 Testing the CATCHER(最长下降子序列)
- POJ-1887-Testing the CATCHER-最长递减子序列-DP动态规划
- poj 1887 Testing the CATCHER (最长不上升子序列)
- POJ--1887:Testing the CATCHER (DP求最长非递增子序列)
- POJ-1887-Testing the CATCHER【最长不上升子序列nlogn】
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
- POJ 1887 —— Testing the CATCHER 最长下降子序列
- PKU1887 Testing the CATCHER (最长不升子序列)
- Testing the CATCHER (最长不升子序列)
- poj 1887 Testing the CATCHER
- JS面向对象的程序设计
- CSS——布局模型
- Android 测试用例的使用
- php5.4.32与php5.5.14 版本中iconv函数IGNORE参数不起作用
- Web服务器(2):自己提供XML数据和Json数据
- POJ 1887 Testing the CATCHER(最长非升子序列)
- android网络应用(二)——HttpURLConnection和HttpClient
- Activiti初学者教程
- 基于Android Studio的内存泄漏检测与解决全攻略
- iOS小技巧22-MacOS 苹果系统下使用MailDrop发送附件(大于20M)
- 在起服务起时候端口被占用,解除占用的命令
- CSS(3) 边框
- Android移植NDK子项目--以android-gif-drawable为例
- 冒泡排序