From 7e1797d2fa7039a5514b15b0b1ac40ae9935f9bd Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 2 Apr 2022 11:44:26 +0800 Subject: [PATCH] =?UTF-8?q?1264.=20=E3=80=90=E4=BE=8B9.8=E3=80=91=E5=90=88?= =?UTF-8?q?=E5=94=B1=E9=98=9F=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://ybt.ssoier.cn:8088/statusx.php?runidx=15564412 --- ybt/1264/1264.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ybt/1264/1264.cpp diff --git a/ybt/1264/1264.cpp b/ybt/1264/1264.cpp new file mode 100644 index 00000000..8a834ffd --- /dev/null +++ b/ybt/1264/1264.cpp @@ -0,0 +1,39 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105; + +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 k = 1; k <= n; k++) { + ans = std::max(ans, f1[k] + f2[k] - 1); + } + + cout << n - ans << endl; + + return 0; +}