From 2611a0d1e03e69f17dcfb29a8a570781771b22f8 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 12 Nov 2021 21:44:08 +0800 Subject: [PATCH] =?UTF-8?q?1017.=20=E6=80=AA=E7=9B=97=E5=9F=BA=E5=BE=B7?= =?UTF-8?q?=E7=9A=84=E6=BB=91=E7=BF=94=E7=BF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/8791523/ --- AcWing/1017/1017.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 AcWing/1017/1017.cpp diff --git a/AcWing/1017/1017.cpp b/AcWing/1017/1017.cpp new file mode 100644 index 00000000..a70b8f02 --- /dev/null +++ b/AcWing/1017/1017.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int t, n, h[105], f[105], ans; + +int main() { + cin >> t; + while (t--) { + ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> h[i]; + } + memset(f, 0x00, sizeof(f)); + 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); + } + ans = max(ans, f[i]); + } + memset(f, 0x00, sizeof(f)); + for (int i = n; i >= 1; i--) { + f[i] = 1; + for (int j = 1; j <= n; j++) { + if (h[i] < h[j]) f[i] = max(f[i], f[j] + 1); + } + ans = max(ans, f[i]); + } + cout << ans << endl; + } + return 0; +}