2.合唱队形 - 蓝桥云课
思路:从左到右找最长单调递增子序列,从右到左找最长单调递增子序列,找它俩和的最大值,和-1就是合唱队形人数最大,人数n-合唱队形人数最大就是我们的答案
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n;
int a[3][N];int main()
{cin >> n;for (int i = 1;i <= n;i++){cin >> a[0][i];a[1][i] = a[2][i] = 1;}for (int i = 1;i <= n;i++){for (int j = i+1;j <= n;j++){if (a[0][i] < a[0][j]){a[1][j] = max(a[1][i]+1,a[1][j]);}}}for (int i = n;i >= 1;i--){for (int j = i-1;j >= 1;j--){if (a[0][i] < a[0][j]){a[2][j] = max(a[2][i]+1,a[2][j]);}}}int res = 0; for (int i = 1;i <= n;i++) res = max(res,a[1][i] + a[2][i] - 1);cout << n - res << endl;return 0;}