40分求助,急急急!

B3637 最长上升子序列

Langrange2021 @ 2024-06-02 20:51:12

#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int num[10001];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> num[i];
    for (int i = 1; i <= n; i++)
    {
        dp[i] = 1;
        for (int j = 1; j <= i; j++)
        {
            if(num[j]<num[i]) dp[i] = max(dp[i], dp[j] + 1);
        }
    }
    cout << dp[n] << endl;
}

我的这个代码为什么只得了40分,各位dl看看呗


by sansesantongshun @ 2024-06-02 21:01:02

应该取dp数组中最大的数,不是dp_n


by Special_Tony @ 2024-06-02 21:15:02

@Langrange2021 最长的不一定以n结尾


|