hdu1257
导弹拦截系统 随时更新dp[i]的值 满足第i个导弹的高度比第j个高的而且dp[i]<dp[j]+1 就更新dp[i]的值
View Code
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int n, i, j, dp[10001], h[10001], min; 6 while(scanf("%d", &n)!=EOF) 7 { 8 for(i = 1 ; i <= n ; i++) 9 { 10 scanf("%d" , &h[i]); 11 dp[i] = 1; 12 } 13 min = 0; 14 for(i = 1 ; i <= n ; i++) 15 { 16 for(j = i-1 ; j >= 0 ; j--) 17 { 18 if(h[i]>h[j]&&dp[i]<dp[j]+1) 19 { 20 dp[i] = dp[j]+1; 21 if(min<dp[i]) 22 min = dp[i]; 23 } 24 } 25 } 26 printf("%d\n", min); 27 } 28 return 0; 29 }