Super Jupmping ! Jumping ! Jumping

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Super Jupmping ! Jumping ! Jumping相关的知识,希望对你有一定的参考价值。

为什么写这一道呢,,,

因为这一道水啊,基础之基础之中的基础啊,,,,然而很简单啊,,,

简单的一道动态规划,最长上升子序列,,,LIS(Longest Increasing Subsequence)

dp[i]表示第i个数结尾的最长上升子序列的长度,,,//这里是数值

初始是dp[i]=1;seg[i]储存第i个数;

状态转移方程dp[i]=max(dp[i],dp[j]+1);

如果seg[j]<seg[i]并且j<i的话,就更新,取最大值;

# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;

int n;
const int maxn=1e3+5;
int dp[maxn],seg[maxn];

int main(){
    while(scanf("%d",&n)!=EOF&&n){
        for(int i=0;i<n;i++)
            scanf("%d",&seg[i]);
        int ans=0;
        for(int i=0;i<n;i++){
            dp[i]=seg[i];
            for(int j=0;j<i;j++){
                if(dp[i]<dp[j]+seg[i]&&seg[j]<seg[i]){
                    dp[i]=max(dp[i],dp[j]+seg[i]);
                }
            }
            ans=max(ans,dp[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

以上是关于Super Jupmping ! Jumping ! Jumping的主要内容,如果未能解决你的问题,请参考以下文章

Super Jumping! Jumping! Jumping!

hdu 1087 Super Jumping! Jumping! Jumping!

Super Jumping! Jumping! Jumping!

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Super Jumping! Jumping! Jumping!(hdu 1087 LIS*)

HDU_1087_Super Jumping! Jumping! Jumping!_dp