Minimum interception system c++

Minimum interception system
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description
A country develops a missile interception system in order to defend against enemy missile attacks. But this missile interception system has a flaw: although its first shell Can reach any height, but each subsequent shell cannot exceed the height of the previous one. One day, the radar picked up the incoming missile from the enemy country. Since the system is still in the trial stage, there is only one system, so it is possible I can't intercept all the missiles.
What should I do? Build a few more systems! It's easy to say, but what about the cost? interception system.

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 group 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
Hint
hdoj1275
Source

#include<stdio.h>
#include<iostream>
#include <iomanip>
using namespace std;

/*实际上是最长上升序列*/
int main()
{
    int n;
    while(cin >> n)
    {
        int a[30000];
        int i,j;
        for(i = 0; i < n ; i++)
        {
            cin >> a[i];
        }
        int b[3000];// = {0};
        b[0] = 1;
        int t;
        //在每一个之前的数进行试探,只要长度增加就改变
        for(i = 1; i < n; i++)
        {
            t = 0;
            for(j = 0; j < i; j++)
            {
                if(a[i] > a[j])
                {
                    if(t <= b[j])
                        t = b[j];
                }
            }
            b[i] = t + 1;
            //cout << "*" << b[i] << endl;
        }
        int mm = b[0];
        for(i = 1; i < n; i++)
        {
            if(b[i] > mm)
                mm = b[i];
        }
        cout << mm << endl;
    }
    //cin >> n;

    return 0;

}

Guess you like

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