mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:48:48 +00:00
1014. 登山
https://www.acwing.com/problem/content/submission/code_detail/8792171/
This commit is contained in:
parent
2611a0d1e0
commit
c35d417c81
29
AcWing/1014/1014.cpp
Normal file
29
AcWing/1014/1014.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user