E-Minimum interception systemTime
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64u Practice HDU 1257
Description
A missile interception system has been developed by a country to defend against enemy missile attacks. But there is a flaw in the 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
enter several sets of data. Each group of data includes: Total number of missiles (positive integers), the height at which the missiles are flown (radar-given height data is a positive integer not greater than 30000, separated by a space)
Output
corresponding to each set of data output intercept all missiles with a minimum of how many sets of this missile interception system.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
Kind of like a DP problem, but more like greed.
0 ms
1#include <stdio.h>2 3 inthigh[ the];4 intdp[ the];5 6 intMain ()7 {8 intN;9 inti,j,k,num,min;Ten while(SCANF ("%d", &n)! =EOF) One { Ascanf"%d", &high[1]); - -dp[1]=high[1];//The first one must have a defense system . thek=1; - - for(i=2; i<=n;i++) - { +scanf"%d",&high[i]); -min=50000; + for(j=1; j<=k;j++) A { at if(dp[j]>high[i]&&dp[j]-high[i]<min)//can intercept - { -min=dp[j]-High[i]; -num=J; - } - } in if(min!=50000) -dp[num]=High[i]; to Else +dp[++k]=High[i]; - } theprintf"%d\n", k); * } $ return 0;Panax Notoginseng}
View Code
(competition) E-minimum interception system