提交时间:2023-11-25 11:20:51
运行 ID: 112266
#include <bits/stdc++.h> using namespace std; int n,a[101],f[101],g[101]; int main() { cin >>n; for(int i = 1; i<= n; i++) { cin >> a[i]; f[i] = g[i] = 1; } for(int i = 2; i <= n; i++) { for(int j = 1; j < i; j++) { if(a[i]>a[j])f[i] = max(f[i],f[j]+1); } } for(int i = n-1; i > 0; i--) { for(int j = n; j > i; j--) { if(a[i]>a[j])g[i]=max(g[i],g[j]+1); } } int maxn = 0; for(int i = 1; i <= n; i++) { maxn = max(f[i]+g[i],maxn); } cout << n-maxn+1; return 0; }