您的位置:首页 > 其它

HDU 1087 Super Jumping! Jumping! Jumping! 动态规划

2013-05-13 21:00 316 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087

Super Jumping! Jumping! Jumping!

[b]Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)[/b]


[align=left]Problem Description[/align]
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.

View Code G++

// File Name: Super Jumping! Jumping! Jumping! 1087.cpp
// Author: sheng
// Created Time: 2013年05月13日 星期一 19时23分17秒

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
#define Max(a, b) (a) > (b) ? (a) : (b)

typedef __int64 LL;
const int max_n = 1010;
long value[max_n];
LL dp[max_n];

int main ()
{
int n;
LL ans;
while (scanf ("%d", &n) == 1, n)
{
//    memset (dp, 0, sizeof (dp));
for (int i = 1; i <= n; i ++)
scanf ("%ld", &value[i]);
ans = dp[1] = value[1];
for (int i = 2; i <= n; i ++)
{
dp[i] = value[i];
for (int j = 1; j < i; j ++)
{
if (value[i] > value[j])
dp[i] = Max(dp[i], dp[j] + value[i]);
}
ans = ans > dp[i] ? ans : dp[i];
}
printf ("%I64d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: