标签:
#include<iostream> #include<vector> #include<algorithm> using namespace std; int DeleteNum(vector<int> &vec); int main() { int N; cin >> N; vector<int> vec; for (int i = 0; i < N; ++i) { int height; cin >> height; vec.push_back(height); } vector<int> DelNum(N, 0); for (int i = 0; i < N; ++i) { vector<int> Left; vector<int> Right; for (int k = 0; k < N; ++k) { if (k <= i) Left.push_back(vec[k]); if (k >= i) Right.push_back(vec[k]); } reverse(Right.begin(), Right.end()); DelNum[i] = DeleteNum(Left) + DeleteNum(Right); } int min = DelNum[0]; for (int i = 0; i < N; ++i) { if (min > DelNum[i]) min = DelNum[i]; } cout << min << endl; return 0; } int DeleteNum(vector<int> &vec) { if (vec.size() == 1) return 0; vector<int> f(vec.size(), 0); int N = vec.size(); f[0] = 1; for (int i = 0; i < N; ++i) { f[i] = 1; for (int j = 0; j < i; ++j) { if (vec[j] < vec[i] && f[j] > f[i] - 1) f[i] = f[j] + 1; } } return N - f[N - 1]; }
标签:
原文地址:http://www.cnblogs.com/VanDiem/p/5616814.html