题面
题解
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n;
int a[N];
int f[N];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
f[i] = 1; //初始以a[i]结尾的上升子序列,开始只有自己
for (int j = 1; j < i; j++) {
if (a[j] < a[i]) {
//枚举前面最后一个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;
}