AcWing 895. 最长上升子序列
原题链接
简单
作者:
chenjiaqiy
,
2023-11-20 23:51:16
,
所有人可见
,
阅读 45
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int n;
int a[N],f[N];
int main ()
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ )//从前往后计算每一个状态
{
f[i] = 1;//表示以i结尾的子序列的长度为1 只有a[i]这一个数
for (int j = 1; j < i; j ++ )
if(a[j] < a[i]) f[i] = max(f[i],f[j] + 1);
}
int res = 0;
for (int i = 1; i <= n; i ++ ) res = max(res,f[i]); //枚举所有中点;
cout << res << endl;
return 0;
}