最大严格递增子序列(非连续)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Let_life_stop/article/details/82872051

题目链接:

https://cn.vjudge.net/contest/68966#problem/E

AC代码:

#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<map>
using namespace std;
# define maxn 1000+10
# define inf 0x3f3f3f3f
# define ll long long
int a[maxn];
int dp[maxn];
int n;
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            dp[i]=a[i];
        }
        int maxx=-inf;
        a[0]=0;
        for(int i=1;i<=n;i++){
        int temp=0;
        for(int j=i;j>=1;j--){
        if(a[j]<a[i]){
        temp=max(temp,dp[j]);
        }
        }
        dp[i]+=temp;
        maxx=max(maxx,dp[i]);
        }
        printf("%d\n",maxx);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Let_life_stop/article/details/82872051