poj 1887 Testing the CATCHER
2013-08-24 16:40
323 查看
题目链接:http://poj.org/problem?id=1887
题目大意:求最长非增子序列的长度
解题思路:简单 dp, 时间复杂度 O(n2), 另有时间复杂度为 O(n·logn) 的算法,读者可自行思考。
题目大意:求最长非增子序列的长度
解题思路:简单 dp, 时间复杂度 O(n2), 另有时间复杂度为 O(n·logn) 的算法,读者可自行思考。
/////////////////////////////////////////////////////////////////////////// //problem_id: poj 1887 //user_id: SCNU20102200088 /////////////////////////////////////////////////////////////////////////// #include <algorithm> #include <iostream> #include <iterator> #include <iomanip> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cmath> #include <queue> #include <stack> #include <list> #include <set> #include <map> using namespace std; /////////////////////////////////////////////////////////////////////////// typedef long long LL; const double PI=acos(-1.0); const int x4[]={-1,0,1,0}; const int y4[]={0,1,0,-1}; const int x8[]={-1,-1,0,1,1,1,0,-1}; const int y8[]={0,1,1,1,0,-1,-1,-1}; typedef int T; T max(T a,T b){ return a>b? a:b; } T min(T a,T b){ return a<b? a:b; } /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //Add Code: /////////////////////////////////////////////////////////////////////////// int main(){ /////////////////////////////////////////////////////////////////////// //Add code: int x,i,j,Case=1,a[50005],dp[50005]; while(scanf("%d",&x)!=EOF){ if(x==-1) break; int n=0; a[++n]=x; while(scanf("%d",&x)!=EOF){ if(x==-1) break; a[++n]=x; } for(i=1;i<=n;i++) dp[i]=1; int Max=1; for(i=2;i<=n;i++){ for(j=1;j<i;j++){ if(a[j]>=a[i]) dp[i]=max(dp[i],dp[j]+1); } Max=max(Max,dp[i]); } if(Case>1) printf("\n"); printf("Test #%d:\n",Case++); printf(" maximum possible interceptions: %d\n",Max); } /////////////////////////////////////////////////////////////////////// return 0; } /////////////////////////////////////////////////////////////////////////// /* Testcase: Input: 389 207 155 300 299 170 158 65 -1 23 34 21 -1 -1 Output: Test #1: maximum possible interceptions: 6 Test #2: maximum possible interceptions: 2 */ ///////////////////////////////////////////////////////////////////////////
相关文章推荐
- POJ 1887 Testing the CATCHER(最长非升子序列)
- poj 1887 Testing the CATCHER_最长上升子序列
- poj 1887 Testing the CATCHER
- POJ 1887-Testing the CATCHER(dp_最长下降子序列)
- POJ 1887 Testing the CATCHER
- POJ 1887 Testing the CATCHER[最长非升子序列O(nlog(n))]
- 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 (最长不上升子序列)
- Testing the CATCHER - POJ 1887 最长递减子序列
- poj 1887 Testing the CATCHER 最长不升子序列
- POJ-1887-Testing the CATCHER【最长不上升子序列nlogn】
- poj 1887 Testing the CATCHER
- POJ 1887:Testing the CATCHER 求递减序列的最大值
- POJ 1887 Testing the CATCHER
- POJ-1887-Testing the CATCHER-最长递减子序列-DP动态规划
- poj 1887 Testing the CATCHER dp 最大降序
- POJ 1887:Testing the CATCHER 求递减序列的最大值