提交时间:2024-04-03 13:50:23

运行 ID: 141318

# include <bits/stdc++.h> using namespace std ; int t [205] , f [205] , g [205] ; int main ( ) { int n , mn ; cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> t [i] ; } memset ( f , 1 , sizeof ( f ) ) ; memset ( g , 1 , sizeof ( g ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) { if ( t [j] < t [i] ) { f [i] = max ( f [i] , f [j] + 1 ) ; } } } for ( int i = n ; i >= 1 ; i -- ) { for ( int j = i + 1 ; j <= n ; j ++ ) { if ( t [j] < t [i] ) { g [i] = max ( g [i] , g [j] + 1 ) ; } } } mn = n ; for ( int i = 1 ; i <= n ; i ++ ) { mn = min ( n - f [k] - g [k] + 1 , mn ) ; } cout << mn << endl ; return 0 ; }