From 1dfbb8ac7e41a51f627a2f98f40e38da011a6a02 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 2 Apr 2022 21:50:01 +0800 Subject: [PATCH] =?UTF-8?q?1286.=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 http://ybt.ssoier.cn:8088/statusx.php?runidx=15575223 --- ybt/1286/1286.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ybt/1286/1286.cpp diff --git a/ybt/1286/1286.cpp b/ybt/1286/1286.cpp new file mode 100644 index 00000000..de2d15b9 --- /dev/null +++ b/ybt/1286/1286.cpp @@ -0,0 +1,47 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105; + +int t, n, a[N], f[N], g[N], ans; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> t; + while (t--) { + ans = 0; + + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int i = 1; i <= n; i++) { + f[i] = 1; + for (int j = 1; j < i; j++) { + if (a[i] > a[j]) f[i] = std::max(f[i], f[j] + 1); + } + } + + for (int i = n; i; i--) { + g[i] = 1; + for (int j = n; j > i; j--) { + if (a[i] > a[j]) g[i] = std::max(g[i], g[j] + 1); + } + } + + for (int i = 1; i <= n; i++) { + ans = std::max({ans, f[i], g[i]}); + } + + cout << ans << endl; + } + + return 0; +}