0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:56:27 +00:00

1283. 登山

http://ybt.ssoier.cn:8088/statusx.php?runidx=15574048
This commit is contained in:
Baoshuo Ren 2022-04-02 21:08:28 +08:00
parent fdaa6957c8
commit 7e859ac796
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

39
ybt/1283/1283.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1005;
int n, a[N], f1[N], f2[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
f1[i] = 1;
for (int j = 1; j < i; j++) {
if (a[i] > a[j]) f1[i] = std::max(f1[i], f1[j] + 1);
}
}
for (int i = n; i; i--) {
f2[i] = 1;
for (int j = n; j > i; j--) {
if (a[i] > a[j]) f2[i] = std::max(f2[i], f2[j] + 1);
}
}
for (int i = 1; i <= n; i++) {
ans = std::max(ans, f1[i] + f2[i] - 1);
}
cout << ans << endl;
return 0;
}