0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 19:45:24 +00:00

1264. 【例9.8】合唱队形

http://ybt.ssoier.cn:8088/statusx.php?runidx=15564412
This commit is contained in:
Baoshuo Ren 2022-04-02 11:44:26 +08:00
parent cc7a253952
commit 7e1797d2fa
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

39
ybt/1264/1264.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <iostream>
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;
}