题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> data(N); for (int i = 0; i < N; i++) { cin >> data[i]; } vector<int> dp1(N, 1), dp2(N, 1); for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { if (data[i] > data[j]) dp1[i] = max(dp1[i], dp1[j] + 1); } } for (int i = N - 1; i >= 0; i--) { for (int j = N - 1; j > i; j--) { if (data[i] > data[j]) dp2[i] = max(dp2[i], dp2[j] + 1); } } int maxn = 0; for (int i = 0; i < N; i++) { if (dp1[i] + dp2[i] - 1 > maxn) maxn = dp1[i] + dp2[i] - 1; } cout << N - maxn; } // 64 位输出请用 printf("%lld")#华为OD机试真题#