代码中的i = 0, j = 0, 全部改成 i = 1, j = 1 是一样的
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
int n;
int f[N], g[N];
int h[N];
int main (){
cin >> n;
for (int i = 0; i < n; i ++) cin >> h[i];
for (int i = 0; i < n; i ++) {
f[i] = 1;
for (int j = 0; j < i; j ++)
if (h[j] < h[i])
f[i] = max(f[i], f[j] + 1);
}
for (int i = n - 1; i > 1; i --) {
g[i] = 1;
for (int j = n - 1; j > i; j --)
if(h[j] < h[i])
g[i] = max(g[i], g[j] + 1);
}
int res = 0;
for (int i = 0; i < n; i ++)
res = max(res, f[i] + g[i] - 1);
cout << n - res << endl;
return 0;
}