求调

B3637 最长上升子序列

wisdom2010 @ 2024-07-27 08:24:16

#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1e5 + 10;
int a[maxn];
int dp[maxn];
int longest;
int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        dp[i] = 1;
    }
    for(int i = 2; i <= n; i++)
    {
        for(int j = 1; j < i; j++)
            if(a[j] <= a[i] && dp[j] + 1 > dp[i])
                dp[i] = dp[j] + 1;
        longest = max(dp[i], longest);
    }
    //printf("%d", dp[n]);
    printf("%d", longest);
    return 0;
}

by wisdom2010 @ 2024-07-27 11:11:02

@DreamInk 哦哦,明白了,谢谢你


by DreamInk @ 2024-07-27 11:13:53

@wisdom2010 是的呢,看看你这么好学,加个关注呗


by wisdom2010 @ 2024-07-27 11:24:09

@DreamInk 嗯嗯,有问题常沟通


上一页 |