最长上升子序列
#include <iostream>
using namespace std;
int main()
{
int a[110], u[110], d[110];
int n, i, j, m;
while ( cin >> n )
{
for( i = 0; i < n; i++)
{
cin >> a[i];
}
/* for( i = 0; i < n; i++)
{
u[i] = 0;
d[i] = 0;
} */
u[0] = 1;
for( i = 1; i < n; i++)
{
u[i] = 1;
for( j = 0; j < i; j++)
{
if( a[j] < a[i] && u[j] + 1 > u[i])
{
u[i] = u[j] + 1;
}
}
/* for( j = 0; j < n; j++)
{
cout << u[j] << " ";
}
cout << endl;*/
}
/* cout << endl;
for( i = 0; i < n; i++)
{
cout << u[i] << " ";
}
cout << endl << endl;; */
d[n - 1] = 1;
for(i = n-2; i >= 0; i--)
{
d[i] = 1;
for( j = n -1; j > i; j--)
{
if(a[j] < a[i] && d[j] + 1 > d[i])
{
d[i] = d[j] + 1;
}
}
/* for( j = 0; j < n; j++)
{
cout << d[j] << " ";
}
cout << endl; */
}
/* cout << endl;
for( i = 0; i < n; i++)
{
cout << d[i] << " ";
}
cout << endl << endl; */
m = 0;
for( i = 0; i < n; i++)
{
if( u[i] + d[i] > m)
{
m = u[i] + d[i];
}
}
m--;
cout << n - m << endl;
}
return 0;
}