POJ-1887-Testing the CATCHER-最长递减子序列-DP动态规划
2011-03-15 22:24
393 查看
跟Longest Ordered Subsequence类似,只不过现在是递减的。再有就是要注意下输入如何进行处理。
动态转移方程为:
dp[i] = max(1, dp[j] + 1), 0 <= j <= i - 1, 且a[j] > a[i]
代码
动态转移方程为:
dp[i] = max(1, dp[j] + 1), 0 <= j <= i - 1, 且a[j] > a[i]
代码
#include <algorithm> #include <iostream> using namespace std; const int MAX_SIZE = 5005; int a[MAX_SIZE]; int dp[MAX_SIZE]; int main() { int test = 1; int temp; while(1) { cin >> temp; if(temp == -1) break; int n = 0; a[0] = temp; n++; while(1) { cin >> temp; if(temp == -1) break; a = temp; n++; } for(int i = 0; i < n; i++) { dp[i] = 1; for(int j = 0; j < i; j++) { if(a[j] > a[i] && dp[i] < dp[j] + 1) dp[i] = dp[j] + 1; } } int max_dp = *max_element(dp, dp + n); cout << "Test #" << test << ":" << endl; cout << " maximum possible interceptions: " << max_dp << endl; cout << endl; test++; } return 0; }
相关文章推荐
- poj 1887 Testing the CATCHER 最长不升子序列
- POJ 1887:Testing the CATCHER 求递减序列的最大值
- POJ 1887:Testing the CATCHER 求递减序列的最大值
- POJ 1887 Testing the CATCHER[最长非升子序列O(nlog(n))]
- Testing the CATCHER - POJ 1887 最长递减子序列
- POJ 1887 Testing the CATCHER 最长不下降序列(LIS)问题
- 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 (最长不上升子序列)
- 【POJ1887 || 2355 || 1631】Testing the CATCHER(最长递增(递减)子序列)NYOJ224
- POJ 1887 —— Testing the CATCHER 最长下降子序列
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
- POJ 1887 Testing the CATCHER(最长下降子序列)
- POJ 1887-Testing the CATCHER(dp_最长下降子序列)
- POJ-1887-Testing the CATCHER【最长不上升子序列nlogn】
- poj 1887 Testing the CATCHER_最长上升子序列
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
- poj 1887 Testing the CATCHER_最长上升子序列