You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 1010 ;
int a [ N ] , f [ N ] ; // 每个导弹的高度, f[i]:以a[i]结尾的最长不升子序列长度
int q [ N ] , ql ; // 需要ql套拦截系统, 每个拦截系统最后一个拦截高度为q[i]
int n , res ;
int main ( ) {
while ( cin > > a [ n ] ) n + + ;
// 第一问
for ( int i = 0 ; i < n ; i + + ) {
f [ i ] = 1 ;
for ( int j = 0 ; j < i ; j + + )
if ( a [ i ] < = a [ j ] ) // 如果前面的比当前的大,说明是不升序列
f [ i ] = max ( f [ i ] , f [ j ] + 1 ) ;
res = max ( res , f [ i ] ) ;
}
// 第二问
for ( int i = 0 ; i < n ; i + + ) {
int p = lower_bound ( q , q + ql , a [ i ] ) - q ;
if ( p = = ql ) // 如果没有找到可以接在后面的导弹拦截系统,那么需要创建一套新的拦截系统
q [ ql + + ] = a [ i ] ;
else
q [ p ] = a [ i ] ; // 否则就直接接到找到的第k套拦截系统的后面,那么, 第k套拦截系统的最后一个拦截高度=q[k]=h[i]
}
// 输出最长不升序列长度,即:最多能拦截的导弹数
printf ( " %d \n %d \n " , res , ql ) ;
return 0 ;
}