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