hdu 1257 一共要多少套拦截系统 (LIS)
给出导弹的高度 拦截的导弹会比上一次低 至少要几套拦截系统才能防御所有导弹
求一套系统能防御的最大导弹数: 反向LIS
求一共要多少套:正向LIS
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # define LL long long 7 using namespace std ; 8 9 int a[100010] ; 10 int f[100010] ; 11 //int dp[100010] ; 12 int n ; 13 14 int bsearch(int size, const int &a) { 15 int l=0, r=size-1; 16 while( l <= r ){ 17 int mid = (l+r)/2; 18 if( a > f[mid-1] && a <= f[mid] ) return mid;// >&&<= 换为: >= && < 19 else if( a < f[mid] ) r = mid-1; 20 else l = mid+1; 21 } 22 } 23 24 int LIS() 25 { 26 int i, j, size = 1; 27 f[0] = a[0]; 28 //dp[0] = 1; 29 for( i=1; i < n; ++i ) 30 { 31 if( a[i] <= f[0] ) j = 0; // <= 换为: < 32 else if( a[i] > f[size-1] ) j = size++;// > 换为: >= 33 else j = bsearch(size, a[i]); 34 f[j] = a[i]; 35 //dp[i] = j+1; 36 } 37 return size; 38 } 39 40 41 int main () 42 { 43 //freopen("in.txt","r",stdin) ; 44 while(scanf("%d" , &n) !=EOF) 45 { 46 int i ; 47 for (i = 0; i < n ; i++) 48 scanf("%d" , &a[i]) ; 49 printf("%d\n" , LIS()) ; // 求最大递增/上升子序列(如果为最大非降子序列,只需把上面的注释部分给与替换) 50 } 51 52 53 return 0 ; 54 }