n^2 dp
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef pair<int, int> pii;
mt19937_64 rng(random_device{}());
void solve() {
int n;
cin >> n;
vector<int> arr(n);
for (auto &e : arr)
cin >> e;
vector<int> dp(n, 1);
int ans = 1;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (arr[j] >= arr[i]) {
dp[j] = max(dp[j], dp[i] + 1);
ans = max(ans, dp[j]);
}
}
}
cout << ans << '\n';
}
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
2025年8月14日大约 1 分钟