标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24667 Accepted Submission(s):
9670
#include<stdio.h> int main() { int m; while(~scanf("%d",&m)) { const int INF=30000;//初始化为全部能拦截; int i,heigh[1000],cmp[1000]; for(i=0;i<m;i++) { scanf("%d",&heigh[i]); cmp[i]=INF; } int j; for(i=0;i<m;i++) { for(j=0;j<=i;j++) { if(cmp[j]>=heigh[i]) { cmp[j]=heigh[i]; break; } } } int total=0; for(i=0;i<m;i++) { if(cmp[i]!=INF)//每个数组元素都看作一套系统; total++; } printf("%d\n",total); } return 0; }
//dp
#include<stdio.h> int main() { int m; while(~scanf("%d",&m)) { int i,heigh[1000],dp[1000]; for(i=0;i<m;i++) { scanf("%d",&heigh[i]); dp[i]=1; } int j; for(i=1;i<m;i++)//核心,将每个系统所能拦截导弹高度标号,取dp[i]最大值; { for(j=0;j<i;j++) { if(heigh[i]>heigh[j]&&dp[i]<dp[j]+1) dp[i]=dp[j]+1; } } int max=dp[0]; for(i=0;i<m;i++) { if(dp[i]>max) max=dp[i]; } printf("%d\n",max); } return 0; }
//路在前方;
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4556467.html