题目链接:http://poj.org/problem?id=2533
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 35605 | Accepted: 15621 |
Description
Input
Output
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
Source
题意:求最长上升子序列长度
题解:DP 这题我WA了两发.....~~~~(>_<)~~~~
AC代码:
#include<iostream>
#include<cstring>
#define N 1005
using namespace std;
int dp[N],num[N],n;
int main()
{
cin.sync_with_stdio(false);
while(cin>>n){
int res=1;
for(int i=0;i<n;i++)dp[i]=1;
for(int i=0;i<n;i++)cin>>num[i];
for(int i=1;i<n;i++){
for(int j=0;j<i;j++){
if(num[i]>num[j])dp[i]=max(dp[i],dp[j]+1);
else if(num[i]==num[j])dp[i]=max(dp[i],dp[j]);
}
if(res<dp[i])res=dp[i];
}
cout<<res<<endl;
}
return 0;
}
POJ 2533 Longest Ordered Subsequence
原文地址:http://blog.csdn.net/mummyding/article/details/43539911