100分求掉

B3637 最长上升子序列

madicine_killer_king @ 2024-05-14 13:13:36

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

by llxsmy_forever @ 2024-05-14 13:33:58

<,不是<=


by llxsmy_forever @ 2024-05-14 13:34:47

我说第12行,改了就过了 @madicine_killer_king


by kehaoyang @ 2024-05-20 08:35:35

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

就过了


|