求助

B3637 最长上升子序列

white_white @ 2024-10-22 13:51:26

零分


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

by one_four_three @ 2024-10-22 14:28:22

@white_white

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

求壶关


by white_white @ 2024-10-22 16:30:54

@one_four_three 谢谢


by white_white @ 2024-10-22 16:32:07

@one_four_three 已互关


|