0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 20:16:29 +00:00

P1091 [NOIP2004 提高组] 合唱队形

R72624461
This commit is contained in:
Baoshuo Ren 2022-03-28 18:52:52 +08:00
parent 9675b07460
commit 31044bbf61
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

40
Luogu/P1091/P1091.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <cstring>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105;
int n, a[N], f[N], g[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++) {
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 >= 1; 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] - 1);
}
cout << n - ans << endl;
return 0;
}