题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
//https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4?tpId=37&rp=1&ru=%2Fexam%2Foj%2Fta&qru=%2Fexam%2Foj%2Fta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D50%26tpId%3D37%26type%3D37&difficulty=&judgeStatus=&tags=&title=24&gioEnter=menu #include <iostream> #include <vector> using namespace std; int main() { int n = 0; while(cin >> n){ vector<int> height(n, 0); int maxn = 0; int dp1[n], dp2[n]; for(int i = 0;i<n;i++) cin >> height[i]; for(int i = 0;i<n;i++){ dp1[i] = 1; for(int j = 0;j<i;j++) if(height[j]<height[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(height[j]<height[i]) dp2[i] = max(dp2[i], dp2[j]+1); } for(int i = 0;i<n;i++) maxn = max(maxn, dp1[i]+dp2[i]-1); cout << n-maxn; } }