Minimum interceptors // HDU - 1257 // dp

Minimum interceptors // HDU - 1257 // dp


topic

A country in order to defend against enemy missile attacks, to develop a missile interception system, but such a missile interceptor system has a flaw: Although it's the first rounds to reach any height, but each shell and should not exceed the previous hair height. One day, the enemy radar missile struck. As the system is still in beta, so only a system, and therefore may not intercept all the missiles.
how to do it? multi engage in several systems chant! you talk about Daoman easy, cost it cost is a big problem ah so Anjiu here to help, please help calculate how many sets of interception system requires a minimum?..
the input
enter several sets of data each set of data including: a total missile number (positive integer), so the missile flying height (the height of the radar data given is a positive integer of not greater than 30,000, separated by spaces)
the output
data corresponding to each block all output sets the minimum number of missiles with the missile to intercept system.
the Sample the Input
. 8 389 207 65 158 155 300 299 170.
the Sample the Output
2
Link: https: //vjudge.net/contest/349029#problem/E

Thinking

If you own any of a number larger than the front, so that if the number of front groups as the highest ground missile that is more than a need to take up this missile interceptors. State transition equation is if (a [i]> a [j]) dp [i] = max (dp [i], dp [j] +1);

Code

#include <cstdio>
#include<algorithm>
#define N 30001
using namespace std;
const int inf = 0x3f3f3f3f;

int a[10000],dp[10000];
int main()
{
    int n;
    a[0]=inf;
    while (scanf("%d",&n)!= EOF){
        for (int i=1;i<=n;i++){
            dp[i]=1;
            scanf("%d", &a[i]);
        }
        for (int i=1;i<=n;i++){
            for (int j=1;j<=i;j++){
                if (a[i]>a[j])
                    dp[i]=max(dp[i],dp[j]+1);
            }
        }
        int ans=0;
        for (int i=1;i<=n;i++)
            ans = max(ans,dp[i]);
        printf("%d\n",ans);
    }
    return 0;
}

note

Published 33 original articles · won praise 9 · views 2054

Guess you like

Origin blog.csdn.net/salty_fishman/article/details/104211105