题解 | #合唱队形#
合唱队形
https://www.nowcoder.com/practice/cf209ca9ac994015b8caf5bf2cae5c98
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { int a[10001]; int max_h = 0; int max_i = 0; for (int i = 0; i < n; i++) { cin >> a[i]; // if (max_h < a[i]) { // max_h = a[i]; // max_i = i; // } } int l[1001]; for (int i = 0; i <n; i++) { l[i] = 1; for (int j = 0; j < i; j++) { if (a[i] > a[j])l[i] = max(l[j] + 1, l[i]); } } int r[1001]; for(int i=n-1;i>=0;i--){ r[i] = 1; for(int j=n-1;j>i;j--){ if (a[i] > a[j])r[i] = max(r[j] + 1, r[i]); } } int ans=1e7; for(int i=0;i<n;i++){ ans=min(ans,n-l[i]-r[i]+1); } // cout<<l[max_i]<<" "<<r[max_i]<<endl; cout<<ans<<endl; } } // 64 位输出请用 printf("%lld")