AcWing 1014. 登山

#include<iostream>
using namespace std ;
const int N=1100;
int f[N],g[N];
int w[N];
int main() {
    int n;
    cin>>n;
    int  res=0;
    for(int i=1; i<=n; i++) cin>>w[i];
    for(int i=1; i<=n; i++) {
        f[i]=1;
        for(int j=1; j<i; j++) {
            if(w[i]>w[j]) f[i]=max(f[i],f[j]+1);
        }
    }
    for(int i=n; i>=1; i--) {
        g[i]=1;
        for(int j=n; j>i; j--) {
            if(w[i]>w[j]) g[i]=max(g[i],g[j]+1);
        }
    }
    for(int i=1; i<=n; i++) res=max(res,f[i]+g[i]-1);
    cout<<res<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/QingyuYYYYY/p/11945437.html