40 悬关

B3637 最长上升子序列

shilige_small @ 2024-12-03 20:50:09

#include<bits/stdc++.h>
using namespace std;
long long n,a[11000],dp[1100000],ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    dp[1]=1;
    for(int i=2;i<=n;i++)
        for(int j=1;j<=i;j++)
        {
            if(a[j]<a[i])
                dp[i]=max(dp[i],dp[j]+1);
            ans=max(dp[i],ans);
        }
    cout<<ans;      
    return 0;
}

by iranai @ 2024-12-03 20:57:37

@shilige_small dp数组应该全部初始化为1


by pies_0x @ 2024-12-03 20:57:56

@shilige_small ans 初始化为 1


by shilige_small @ 2024-12-03 21:03:19

谢谢 已关


|