(competition) E-minimum interception system

Source: Internet
Author: User
Tags radar

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.