提交时间:2023-11-25 16:38:07

运行 ID: 112332

#include<bits/stdc++.h> using namespace std; int dp[114],pd[114],a[114514],maxn; int main(){ int n; cin>>n; for (int i = 1;i <= n;i++){ cin>>a[i]; dp[i] = 1; pd[i] = 1; } for (int i = n - 1;i >= 1;i--){ for (int j = i + 1;j <= n;j++){ if (a[i] > a[j]){ pd[i] = max(pd[i],pd[j] + 1); } } } for (int i = 2;i <= n;i++){ for (int j = 1;j < i;j++){ if (a[i] > a[j]){ dp[i] = max(dp[i],dp[j] + 1); } } } for (int i = 1;i <= n;i++){ maxn = max(maxn,dp[i] + pd[i] - 1); } cout<<n - maxn<<endl; return 0; }