From 7e859ac7968fef9ec20ee58a7781a714d648482a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 2 Apr 2022 21:08:28 +0800 Subject: [PATCH] =?UTF-8?q?1283.=20=E7=99=BB=E5=B1=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://ybt.ssoier.cn:8088/statusx.php?runidx=15574048 --- ybt/1283/1283.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ybt/1283/1283.cpp diff --git a/ybt/1283/1283.cpp b/ybt/1283/1283.cpp new file mode 100644 index 00000000..1f626e59 --- /dev/null +++ b/ybt/1283/1283.cpp @@ -0,0 +1,39 @@ +#include + +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; +}