您的位置:首页 > 其它

HDU 1087 Super Jumping! Jumping! Jumping!

2014-11-04 13:07 274 查看
这个题一看就是找一个 递增子序列。。 然后脑残的以为找 最长上升子序列。 在模板里面加上个 sum 数组递推上 过了样例就交上去了

获得了 WA之后。 自己出了一组数据 3 2 1 8 9 这五个数 最长上升子序列 有三个 3 89 或者 2 8 9 或者 1 8 9 然后就没法处理。

后来一想 应该是 上升子序列中找和最大的。 就写出 n^2 的递推公式了。 s【i】 = max (s【i】,s【j】 + a【i】) 其中 s【i】 代表以第i个数为结尾的最大和。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long LL;
typedef unsigned long long LLU;
const double PI=acos(-1.0);
using namespace std;
#define MAXN 1000+10
#define INF 1 << 30
int main (){
    int n;
    while(scanf("%d",&n) && n){
        LL a[MAXN];
        LL s[MAXN] = {0};
        for(int i = 1; i <= n; i++){
            scanf("%I64d",&a[i]);
            s[i] = a[i];
        }
        LL M = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= i; j++){
                if(a[i] > a[j])
                    s[i] = max(s[i], s[j]+a[i]);
            }
        }
        for(int i = 1; i <= n; i++)
            M = max(M, s[i]);
        printf("%I64d\n",M);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: