40pts

B3637 最长上升子序列

valen071 @ 2024-10-19 19:07:38

#include <bits/stdc++.h>
using namespace std;
#define int long long
int f[10010],n,a[100010];
signed main(){
    cin >> n;
    f[1]=1;
    for(int i=1;i<=n;i++)cin >> a[i];
    for(int i=2;i<=n;i++){
        int m=-1e9;
        f[i]=1;
        for(int j=i;j>=1;j--){
            if(f[j]>m&&a[j]<a[i]){
                f[i]=f[j]+1;
                m=f[j];
            }
        }
    }
    cout << f[n];
    return 0;
}

by valen071 @ 2024-10-19 19:08:56

哦哦哦我懂了


|