40tps求助TVT

B3637 最长上升子序列

Jokersheng @ 2025-01-12 11:59:18

#include <bits/stdc++.h>
using namespace std;

const int N=5050;

int n,a[N],s[N],maxx;

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    s[n]=1;
    for(int i=n-1;i>=1;i--){
        maxx=INT_MIN;
        for(int j=i+1;j<=n;j++){
            if(maxx<s[j]&&a[i]<a[j]){
                maxx=s[j];
            }
        }
        s[i]=max(0,maxx+1);
    }
    maxx=INT_MIN;
    for(int i=1;i<=n;i++){
        maxx=max(maxx,s[i]);
    }
    cout<<maxx;
    return 0;
}

|