e~ Minimum interception system

Source: Internet
Author: User
Tags radar

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 idea: directly to find the maximum number of each missile interception system currently can intercept and intercept all the interception, note that there is no way to intercept the maximum number of, but once you can intercept, then intercept and search for lower. If the height of the rear shell is lower than the height of the previous one, it is a good DP topic, and there are two other solutions that need to be further thought about the AC code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace Std;
int a[10010],v[10010];
int main ()
{
int n,ans,min;
while (~SCANF ("%d", &n))
{
memset (v,0,sizeof (v));
for (int i=1;i<=n;i++)
scanf ("%d", &a[i]);
ans=0;
for (int i=1;i<=n;i++)
{
if (!v[i])
{
V[i]=1;
ans++;
Min=a[i];
for (int j=1+i;j<=n;j++)
if (!v[j]&&a[j]<min)
{
V[j]=1;
MIN=A[J];
}
}
}
printf ("%d\n", ans);
}
return 0;
}

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.