最长上升子序列问题
状态表示: 集合:所有以第i个数结尾的上升子序列,属性:Max\
状态计算: 集合的划分:以i - 1个数结尾划分
f[i] = max(f[j] + 1),aj < ai(j = 0,1,2,3......i-1)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1010;
int n,res;
int a[N];
int f[N];
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;++i) scanf("%d",&a[i]);
for(int i = 1;i <= N;++i){
f[i] = 1;
for(int j = 1;j < i;++j){
if(a[j] < a[i]) f[i] = max(f[i],f[j] + 1);
}
}
for(int i = 1;i <= n;++i) res = max(res,f[i]);
printf("%d\n",res);
return 0;
}