From 50e83048ff1bb574c2575c27eded2437205eb98b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 1 Apr 2022 17:10:42 +0800 Subject: [PATCH] =?UTF-8?q?1259.=20=E3=80=90=E4=BE=8B9.3=E3=80=91=E6=B1=82?= =?UTF-8?q?=E6=9C=80=E9=95=BF=E4=B8=8D=E4=B8=8B=E9=99=8D=E5=BA=8F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://ybt.ssoier.cn:8088/statusx.php?runidx=15557056 --- ybt/1259/1259.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ybt/1259/1259.cpp diff --git a/ybt/1259/1259.cpp b/ybt/1259/1259.cpp new file mode 100644 index 00000000..f2938b3a --- /dev/null +++ b/ybt/1259/1259.cpp @@ -0,0 +1,45 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 205; + +int n, a[N], f[N], r[N], t, ans; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[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); + } + + if (f[i] > ans) { + ans = f[i]; + t = i; + } + } + + cout << "max=" << ans << endl; + + for (int i = t; i; i--) { + if (f[i] == ans && a[i] <= a[t]) { + f[i] = 0; + ans--; + t = i; + } + } + + for (int i = 1; i <= n; i++) { + if (!f[i]) cout << a[i] << ' '; + } + cout << endl; + + return 0; +}