ACM Minimum Interception System

In order to defend against enemy missile attacks, a country has developed a missile interception system. However, this missile interception system has a defect: although its first shell can reach any height, each subsequent shell cannot exceed the previous one. One day, the radar captured the incoming missile from the enemy country. Since the system is still in the trial stage, there is only one system, so it may not be able to intercept all the missiles.
What should I do? Develop more systems! It's easy for you to say, but what about cost? Cost is a big problem. So I came here to ask for help, please help calculate the minimum number of interception systems required.

Input Input several sets of data. Each set of data includes: the total number of missiles (positive integer), and the altitude of the missile flying accordingly (the altitude data given by the radar is a positive integer not greater than 30000, separated by spaces)
Output Corresponds to each set Data output The minimum number of such missile interception systems required to intercept all missiles.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int n,x,a[10000];
    while(cin>>n){
        memset(a,0,sizeof(a));
        cin>>a[0];
        for(int i=2,j=1;i<=n;i++){
            cin>>x;
            for(j=1;j<i;j++){
                if(x<=a[j]){//Can intercept
                    a[j]=x;
                    break;
                }
            }
            if(j==i){//Cannot intercept
                a[i]=x;
            }
        }
        int flag=0;
        for(int i=1;i<=n;i++){
            if(a[i]!=0)
                flag++;
        }
        cout<<flag<<endl;
    }
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325669888&siteId=291194637