HDOJ-1087 Super Jumping! Jumping! Jumping!

最大上升子序列,做法和最长上升子序列类似

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
int dp[1005], num[1005];

int main()
{
   // freopen("in.txt", "r", stdin);
    int n;

    while(cin >> n && n)
    {
        for(int i = 0; i < n; i++)
        {
            cin >> num[i];
            dp[i] = num[i];
        }

        int maxs = dp[0];
        for(int i = 1; i < n; i++)
        {
            for(int j = 0; j < i; j++)
            {
                if(num[i] > num[j])
                    dp[i] = max(dp[i], dp[j] + num[i]);
            }
            maxs = max(maxs, dp[i]);
        }
        cout << maxs << endl;
    }
    return 0;
}

你可能感兴趣的:(HDOJ-1087 Super Jumping! Jumping! Jumping!)