HDU 1087 Super Jumping! Jumping! Jumping!(DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087


题目大意:求出上升子序列的最大和


解题思路: 最长上升子序列


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1111;
__int64 dp[maxn];
int num[maxn];
int main ()
{
    int n;
    while(scanf("%d", &n), n)
    {
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &num[i]);
            dp[i] = num[i];
        }

        for(int i = 1; i <= n; i++)
        {
            __int64 Max = 0;
            for(int j = 1; j < i; j++)
            {
                if(num[j] < num[i])
                    Max = max(Max, dp[j]);
            }
            dp[i] += Max;
        }

        __int64 ans = 0;
        for(int i = 1; i <= n; i++)
            ans = max(ans, dp[i]);
        printf("%I64d\n", ans);
    }
    return 0;
}


你可能感兴趣的:(dp)