40分,求调

B3637 最长上升子序列

Mei20 @ 2024-10-26 11:32:24

#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a[5005],f[5005];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    f[1]=1;
    for(int i=2;i<=n;i++)
    {
        f[i]=1;
        for(int j=1;j<=i-1;j++)
        {
            if(a[j]<a[i])
            f[i]=max(f[i],f[j]+1);
        }
    }
    printf("%d",f[n]);
    return 0;
}

by WillHou @ 2024-10-26 11:50:10

输出 \max {f_i} 而非 f_n


|