40pts,记忆化dfs求助

B3637 最长上升子序列

Math_Miss @ 2023-10-14 12:33:44

#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000001],b[1000001];
int f[1000001];
int dfs(int step){
    if(f[step]){
        return f[step];
    }
    for(int i=1;i<=step;i++){
        if(a[step]>a[i]){
            f[step]=max(f[step],f[i]+1);
        }
        //f[step]=max(f[step],f[i]);
    }
    return f[step];
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }

    f[1]=1;

    int maxn=-2147483648;
    for(int i=1;i<=n;i++){
        maxn=max(dfs(i),maxn);
    }
    printf("%d",maxn);
    return 0;
}

by Math_Miss @ 2023-10-15 09:53:39

不在线,不会按时回复,请谅解


by Math_Miss @ 2023-10-15 09:56:42

已经AC,抱歉打扰


|