本文主要是介绍POJ 2533 LIS N2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 34360 | Accepted: 15083 |
Description
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
Output
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
Source
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int a[1001],dp[1001];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(cin>>n)
{
for(int i=1;i<=n;i++)
cin>>a[i];
a[0]=-1;
cle(dp);
int ans=-1;
for(int i=1;i<=n;i++)//4 0 1 2 3
{
for(int j=0;j<i;j++)
if(a[i]>a[j])dp[i]=max(dp[i],dp[j]+1);
ans=max(dp[i],ans);
}
cout<<ans<<endl;
}
return 0;
}
这篇关于POJ 2533 LIS N2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!