#include <iostream>
#include <cstring>
using namespace std;
typedef long int li;
const int size = 201;
int n;
li arr[size];
int dp[size][size][size];
int main()
{
while(true)
{
cin >> n;
if(n == -1)
break;
for(int i = 1; i <= n; i++)
cin >> arr[i];
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= n; i++)
{
for(int lb = i + 1; lb <= n + 1; lb++)
{
for(int lw = i + 1; lw <= n + 1; lw++)
{
dp[i][lb][lw] = dp[i - 1][lb][lw] + 1;
if(lb > n || arr[i] < arr[lb])
{
dp[i][lb][lw] = min(dp[i][lb][lw], dp[i - 1][i][lw]);
}
if(lw > n || arr[i] > arr[lw])
{
dp[i][lb][lw] = min(dp[i][lb][lw], dp[i - 1][lb][i]);
}
}
}
}
cout << dp[n][n + 1][n + 1] << endl;
}
return 0;
}
Comments
Post a Comment