题目描述
blablabla
算法1
(暴力枚举) $O(n^2)$
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int N[110], f[110], g[110];
int n, x, s = 1;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
N[i] = x;
f[i] = 1;
g[i] = 1;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < i; j++)
{
if (N[i]>N[j])
f[i] = max(f[i], f[j] + 1);
}
}
for (int i = n - 1; i >= 0; i--)
{
for (int j = n-1; j > i; j--)
{
if (N[i]>N[j])
g[i] = max(g[i], g[j] + 1);
}
}
for (int i = 0; i < n; i++)
s = max(s, f[i] + g[i] - 1);
cout << n - s;
return 0;
}