From c35d417c815bf7199f0a09a5837c028d583f612d Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 12 Nov 2021 22:08:50 +0800 Subject: [PATCH] =?UTF-8?q?1014.=20=E7=99=BB=E5=B1=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/8792171/ --- AcWing/1014/1014.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 AcWing/1014/1014.cpp diff --git a/AcWing/1014/1014.cpp b/AcWing/1014/1014.cpp new file mode 100644 index 00000000..81d4fe8d --- /dev/null +++ b/AcWing/1014/1014.cpp @@ -0,0 +1,29 @@ +#include + +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; +}