Problem Description

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.
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.

Input

Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N 
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.

Output

For each case, print the maximum according to rules, and one line one case.

Sample Input

3 1 3 2
4 1 2 3 4
4 3 3 2 1
0

Sample Output

4
10
3
解题思路:题意就是求单调递增子序列的最大和,数据比较小,改一下LIS的O(n^2)算法模板即可。
AC代码(15ms):
 #include<bits/stdc++.h>
using namespace std;
int n,maxsum,s[],dp[];
int main(){
while(~scanf("%d",&n)&&n){
memset(dp,,sizeof(dp));maxsum=;
for(int i=;i<n;++i)scanf("%d",&s[i]),dp[i]=s[i];//每个s[i]都是一个递增子序列的开始
for(int i=;i<n;++i){
for(int j=;j<i;++j)
if(s[j]<s[i])dp[i]=max(dp[i],dp[j]+s[i]);//构成递增子序列,更新其和值
maxsum=max(maxsum,dp[i]);//更新最大值
}
printf("%d\n",maxsum);
}
return ;
}

题解报告:hdu 1087 Super Jumping! Jumping! Jumping!的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping

    HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...

  2. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...

  3. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...

  4. HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  5. hdu 1087 Super Jumping! Jumping! Jumping!(最大上升子序列和)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)

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

  7. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  8. hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

随机推荐

  1. linux迁移至固态硬盘全过程

    自从台式机上用上固态硬盘后,就再也受不了笔记本上的5400转的机械硬盘了,所以这次又买了块固态硬盘打算装到笔记本上. 笔记本里装的是Ubuntu 14.04 + Win7双系统,Win7主要偶尔运行一 ...

  2. [NPM] npm check to update the dependencies

    To update the dependencies in the project, we can run: npx npm-check -u

  3. XP 系统如何安装.NET Framework4.0

    1 运行CMD,然后输入命令net stop WuAuServ   2 打开C盘的Windows目录,然后找到SoftwareDistribution文件夹改名为SDold.   3 在CMD窗口中输 ...

  4. Java中常见的排序算法

    这是我摘取的一段英文资料.我认为学习算法之前,对各种排序得有个大致的了解: Sorting algorithms are an important part of managing data. At ...

  5. 国内博客(blog)搬家工具(服务)大全

    如今网络上的博客搬家 服务,博客搬家工具 越来越多,博客联盟 大概收集了下,希望对那些想搬家的博客有所帮助. 一.和讯博客的“搬家公司”提供博客搬家 服务 搬家服务地址:点这里 目标对象:新浪博客 . ...

  6. 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何

    基于 Vue.js 之 iView UI 框架非工程化实践记要   像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引 ...

  7. C#结构类型图

    C#结构类型图     分类: C#

  8. rocketmq消费队列代码

    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(Constant.operationLogGroup); try { consum ...

  9. Linux_C——动态库,静态库

    /usr/lib /lib:标准系统库文件          库是一组预先编译好的函数的集合,这些函数都是按照可重用的原则编写的.它们通常有一组相互关联的函数组成以          执行某项常见的任 ...

  10. Codeforces 480B Long Jumps 规律题

    题目链接:点击打开链接 题意: 输出n l x y 有一根直尺长度为l 上面有n个刻度. 以下n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l) 要使得 直尺中存在某2个刻度的距离为x ...