最近在做DP,好好静下心来学习吧....
首尾两次最长升序子序列= =,好吧 很水..
#include<iostream>
using namespace std;int max( int a,int b ){ return a>b?a:b; }int main()
{int N;int high[101];int DP1[101],DP2[101];memset( DP1,0,sizeof(DP1) );memset( DP2,0,sizeof(DP2) );scanf( "%d",&N );for( int i=1;i<=N;i++ )scanf( "%d",&high[i] );for( int i=1;i<=N;i++ ){for( int j=1;j<i;j++ )if( high[i]>high[j] )DP1[i]=max( DP1[i],DP1[j] );DP1[i]++;}for( int i=N;i>=1;i-- ){for( int j=i+1;j<=N;j++ )if( high[i]>high[j] )DP2[i]=max( DP2[i],DP2[j] );DP2[i]++;}int ans=0;for( int i=1;i<=N;i++ )ans=max( DP1[i]+DP2[i],ans );printf( "%d\n",N-ans+1 );return 0;
}