Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1257
Minimum interception system
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 28771 Accepted Submission (s): 11328
Problem description A missile interception system developed by a country to defend against enemy missile attacks. But there is a flaw in this missile interception system: Although its first shells can reach any height, each shot cannot exceed the height of the previous one. Someday, The radar captures the enemy's missiles. Since the system is still in trial, there is only one set of systems that may not intercept all missiles.
What do we do? How many systems do you have? It's easy to say it. Cost is a big problem. So I came here to call for help, please figure out how many sets of interception systems you need at least.
Input enters several sets of data. Each group of data includes: Total number of missiles (positive integers), the height at which missiles fly (radar-given height data is a positive integer not greater than 30000, separated by a space)
Output corresponds to each set of data outputs to intercept all missiles with a minimum of how many sets of such missile interception systems.
Sample INPUT8 389 207 155 300 299 170 158 65
Sample Output2
SOURCE Zhejiang University of Technology The fourth session of college students Program design contest Greed:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespacestd;Const intOO =1e9;intdp[100005];inta[100005];intMain () {intN; while(~SCANF ("%d",&N)) { for(intI=1; i<=n; i++) {scanf ("%d", &A[i]); } intx = a[1]; intAns =1; dp[1] = a[1]; for(intI=1; i<=n; i++) { intFlag =0; intMin =Oo; intT; for(intj=1; j<=ans;j++) { if(Dp[j]>=a[i] && min>dp[j]-A[i]) {Min= dp[j]-A[i]; T=J; Flag=1; } } if(flag) {Dp[t]=A[i]; } Else{dp[++ans] =A[i]; }} printf ("%d\n", ans); } return 0;}
HDU 1257 Minimum interception system