【dp每日一题】HDU 1087 Super Jumping! Jumping! Jumping!

大意:

求最大权值上升子序列

思路:

把最大上升子序列的板子改改就行,dp[i]代表以i为结尾的上升子序列的权值

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int n, a[N], dp[N];
int main() {
    while (scanf("%d", &n) && n != 0) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            dp[i] = a[i];
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (a[j] < a[i]) {
                    dp[i] = max(dp[j] + a[i], dp[i]);
                }
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            res = max(res, dp[i]);
        }
        cout << res << endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14187048.html