lby_commandBlock @ 2024-05-03 09:40:58
rt
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 5009;
int n, a[N], dp[N], len;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[1] = a[1];
len = 1;
for (int i = 1; i <= n; i++) {
if (a[i] > dp[len]) {
dp[++len] = a[i];
} else if (a[i] < dp[len]) {
int p = upper_bound(dp + 1, dp + 1 + len, a[i]) - dp;
dp[p] = a[i];
}
}
cout << len << endl;
return 0;
}
by Bingxiu @ 2024-05-03 09:55:56
@lby_commandBlock 确定不是 lower_bound
by Bingxiu @ 2024-05-03 09:56:42
@lby_commandBlock 而且你这 dp 数组为什么没有 memset 为 INF 啊?
by lby_commandBlock @ 2024-05-03 09:58:05
@Bingxiu 此贴结