提交时间:2023-11-29 13:21:36
运行 ID: 112861
#include<bits/stdc++.h> using namespace std; int a[2000],b[2000],c[2000]; int main(){ int n,i,j,maxx; cin>>n; memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(i = 1;i <= n;i++){ cin>>a[i]; } for(i = 1;i <= n;i++){ b[i] = 1; for(j = 1;j <= i - 1;j++){ if((a[i] > a[j]) && (b[j] + 1 > b[i])){ b[i] = b[j] + 1; } } } for(i = n;i >= 1;i--){ c[i] = 1; for(j = i + 1;j <= n;j++){ if((a[j] < a[i]) && (c[j] + 1 > c[i])){ c[i] = c[j] + 1; } } } maxx = 0; for(i = 1;i <= n;i++){ if(b[i] + c[i] > maxx){ maxx = b[i] + c[i]; } } cout<<n - maxx + 1<<endl; }