#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>
///poj2533
#define maxn 1000+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
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int a[maxn];
int dp[maxn];///存放以a[i]为终点的最长子串长度
///状态转移方程为 dp[i]=max(dp[j])+1; 1<=j<=i
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,i,j;
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
cin>>a[i];
dp[i]=1;
}
int Max=0,max1;
for( i=1;i<=n;i++)
{
max1=0;
for( j=1;j<=i;j++)
{
if(a[j]<a[i]&&dp[j]>max1)
max1=dp[j];
}
dp[i]=max1+1;///加上他自己
if(dp[i]>Max)
Max=dp[i];
}
cout<<Max<<endl;
}
return 0;
}
最长上升子序列(LIS)
最新推荐文章于 2022-05-29 08:47:00 发布
http://poj.org/problem?id=2533
LIS裸题