提交时间:2023-11-25 10:40:43
运行 ID: 112140
#include <cmath> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 1010; int w[N], f1[N], f2[N]; int n; void lis(int* f) { for (int i = 1; i<=n; i++) { f[i] = 1; for (int j = 1; j<i; j++) { if (w[j] < w[i]) f[i] = max(f[i], f[j]+1); } } } int main () { cin >> n; for (int i = 1; i<=n; i++) cin >> w[i]; lis(f1); reverse(w+1, w+n+1); lis(f2); int res = 0; for (int i = 1; i<=n; i++) res = max(res, f1[i]+f2[n-i+1]); cout << n-res+1 << endl; return 0; }