#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
const int SIZE = 1003;
double road[SIZE];
int dp1[SIZE];
int dp2[SIZE];
int n;
int main(){
scanf("%d", &n);
for (int i = 0; i <n; ++i) {
scanf("%lf", &road[i]);
}
// LIS seq
memset(dp1, 0, sizeof(dp1));
dp1[0] = 1;
for (int i = 1; i <n ; ++i) {
dp1[i] = 1;
for (int j = 0; j <i ; ++j) {
if (road[i]>road[j])
dp1[i] = max(dp1[i], dp1[j]+1);
}
}
// LDS seq
memset(dp2, 0, sizeof(dp2));
dp2[n-1] = 1;
for (int i = n-2; i >=0 ; --i) {
dp2[i] = 1;
for (int j = i+1; j<n ; ++j) {
if (road[i]>road[j])
dp2[i] = max(dp2[i], dp2[j]+1);
}
}
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
res = max(res, dp1[i]+dp2[j]);
}
}
cout<<n-res<<endl;
}
poj 1836
最新推荐文章于 2019-10-14 00:14:21 发布