标签:
Description
Input
Output
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
//有点像 dp 题, 但是更像 贪心
0 ms
1 #include <stdio.h> 2 3 int high[3000]; 4 int dp[3000]; 5 6 int main() 7 { 8 int n; 9 int i,j,k,num,min; 10 while (scanf("%d",&n)!=EOF) 11 { 12 scanf("%d",&high[1]); 13 14 dp[1]=high[1];//第一个一定要个防御系统 15 k=1; 16 17 for (i=2;i<=n;i++) 18 { 19 scanf("%d",&high[i]); 20 min=50000; 21 for (j=1;j<=k;j++) 22 { 23 if (dp[j]>high[i]&&dp[j]-high[i]<min)//可以拦截 24 { 25 min=dp[j]-high[i]; 26 num=j; 27 } 28 } 29 if(min!=50000) 30 dp[num]=high[i]; 31 else 32 dp[++k]=high[i]; 33 } 34 printf("%d\n",k); 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/haoabcd2010/p/5766082.html