动态规划,最长LIS模板,正反各用一次
ti
#include<bits/stdc++.h>using namespace std;int n;
int a[105], dp1[105], dp2[105];int main()
{while(cin>>n){memset(a, 0, sizeof(0));memset(dp1, 0, sizeof(dp1));memset(dp2, 0, sizeof(dp2));for(int i = 0; i < n; i ++ ) cin>>a[i];for(int i = 0; i < n; i ++ ){dp1[i] = 1;for(int j = 0; j < i; j ++ ){if(a[j] < a[i]){dp1[i] = max(dp1[i], dp1[j] + 1);}}}for(int i = n - 1; i >= 0; i -- ){dp2[i] = 1;for(int j = n - 1; j > i; j -- ){if(a[j] < a[i]){dp2[i] = max(dp2[i], dp2[j] + 1);}}} int ans = 1;for(int i = 0; i < n; i ++ ){ans = max(ans, dp1[i] + dp2[i]);}cout<<n - ans + 1<<endl;}return 0;
}