III missile interceptors

Title Description Many years ago, A country invented a missile system to intercept a missile launch hostile forces. This system can launch a missile to intercept from a far, does not increase the height of multiple missiles.

But now, scientists have found that the defense system is not strong enough, so they invented another set of missile systems. This new system can fire a missile from near to far more interceptor missiles. When the system starts, first select an enemy missile interception, interception and then a further lower the height of the missile to intercept and interception of missile higher than the second but highly stars farther ...... and so on , intercepted particles odd-missile missile farther than the front one, higher even-intercept missile particles farther than a front, lower.

Up to now the number of missiles, to give you a launch a missile from near to far missiles height of the list, the new computing system can intercept.

Input and output format of the input format: the input file missile.in, the first line is an integer n (0 <n≤1000), denotes the number of transmitted enemy missile. The next line there are n integers (≤109), represented by a missile near to far heights.

Output formats: Output file missile.out, only an integer number of interceptor missiles of the largest representation.

Input Output Input Sample # 1 Sample: Copy Output 45324 Sample # 1: Copy 3

 

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[11115],dp[11115][5];

int main () {
     int n years = 0 ;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    dp[1][1]=1;
    for(int i=2;i<=n;i++){
        dp[i][1]=1;
        for(int j=1;j<=i-1;j++){
            if(a[j]<a[i]){
                dp[i][1]=max(dp[i][1],dp[j][0]+1);
            }
            if(a[j]>a[i]){
                dp[i][0]=max(dp[i][0],dp[j][1]+1);
            }
        }
        ans=max(ans,max(dp[i][1],dp[i][0]));
    }
    printf("%d",ans);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11141210.html
Recommended