最长上升子序列-线性dp
重点
1. 尽量尝试用低维数来表示状态方程
2. a[i] 表示以i结尾的所有上升子序列的集合,属性是最大值
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int a[N];
int f[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
f[i] = 1; // 只有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 << endl;
cout << res << endl;
return 0;
}