求助,用动态规划写为什么只有40分

B3637 最长上升子序列

wanttoac @ 2024-01-11 18:21:28

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define maxn 1000000
int d[maxn] = { 1 };
int main() {
    vector<int>nums;
    int num, n;
    cin >> n;
    int maxx = 0;
    for (int i = 0; i < n; i++) {
        cin >> num;
        nums.push_back(num);
    }
    for (int i = 1; i < n; i++) {
        for (int q = 0; q < i; q++) {
            if (nums[q] < nums[i]) {
                d[i] = max(d[i], d[q] + 1);
            }
        }
        if (d[i] > maxx)maxx = d[i];
    }
    cout << maxx;
    return 0;
}

by WZWZWZWY @ 2024-01-11 19:05:12

@shaochang 不一定要选第一个元素。而且你的循环应该是从0到n-1。

并且你的d只有d[0]赋值为1,应该所有的d都赋值为1


by miffy_123 @ 2024-02-23 10:04:24

这题求的是最长不下降序列


by miffy_123 @ 2024-02-23 10:04:58

@wanttoac


|