代码求调·

B3637 最长上升子序列

jms23063 @ 2024-11-11 21:41:48

40分,求调,谢谢。

#include<bits/stdc++.h>
using namespace std;
int d[5050], a[5050];
int main(){
    int n, ans = 0;
    scanf("%d", &n);
    d[1] = 1;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        for(int j = 1; j < i; j++)if(a[i] > a[j])d[i] = max(d[i], d[j]+1);
        ans = max(ans, d[i]);
    }
    cout << ans;
    return 0;
}

by bladrrxy @ 2024-11-11 21:45:35

d每个数都要设成1 @jms23063


by hhztl @ 2024-11-11 21:45:44

@jms23063 给所有 d_i 赋初值 1


by jms23063 @ 2024-11-11 21:48:03

谢谢大家!


|