Hdu 1257 minimum interception system (Greedy)
Minimum Interception SystemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 23724 Accepted Submission (s): 9303
Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1257
Problem Description a country has developed a missile interception system to defend against missile attacks by the enemy. however, this missile interception system has a defect: although its first shell can reach any height, it cannot exceed the height of the previous one. one day, the radar captured the enemy's missiles. because the system is still in the trial phase, there is only one system, so it may not be able to intercept all missiles.
What should we do? How many more systems are involved! It's easy to talk about. What about the cost? The cost is a big problem, so I am here for help. Please help calculate the minimum number of interception systems required.
Input several groups of data. each set of data includes the total number of missiles (positive integers), and the height of missiles flying here (the height data given by the radar is a positive integer not greater than 30000, separated by spaces)
The Output corresponds to the minimum number of missile interceptions required for each set of data Output to intercept all missiles.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
Source Zhejiang University of Technology's fourth college Program Design Competition
I thought it was a simple dp question, but I still couldn't read it for a long time. Later I understood the blogger: http://blog.csdn.net/sr_19930829/article/details/14064525code, greedy
# Include
# Include
Int main () {int n; int a [30010]; int dao [30010]; while (scanf ("% d", & n )! = EOF) {memset (dao, 0, sizeof (dao); scanf ("% d", & dao [1]); // set the first position to the initial Missile interception height (set as the first missile interception system, and the rest are 0 at the beginning) int height; int num = 1; int j; for (int I = 2; I <= n; I ++) {scanf ("% d", & height); for (j = 1; j <= I; j ++) // retrieves {if (height <= dao [j]) from the first missile interception system. // if the height is smaller than that of the interception system, update the interception system, {dao [j] = height; // (retrieve from the first interception system (the lowest height) each time, and intercept with the lowest interception system higher than the current missile) break ;}} if (j> I) // if the height of all interception systems is smaller than the current missile, {dao [++ num] = height; // Add an interception system} printf ("% d \ n", num);} return 0 ;}