0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00
Baoshuo Ren 2021-11-12 22:08:50 +08:00 committed by Baoshuo Ren
parent 2611a0d1e0
commit c35d417c81
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

29
AcWing/1014/1014.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <bits/stdc++.h>
using namespace std;
int n, h[1005], f[1005], g[1005], ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
f[i] = 1;
for (int j = 1; j <= i; j++) {
if (h[i] > h[j]) f[i] = max(f[i], f[j] + 1);
}
}
for (int i = n; i >= 1; i--) {
g[i] = 1;
for (int j = n; j >= i; j--) {
if (h[i] > h[j]) g[i] = max(g[i], g[j] + 1);
}
}
for (int i = 1; i <= n; i++) {
ans = max(ans, f[i] + g[i] - 1);
}
cout << ans << endl;
return 0;
}