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

就是找最大的递增子序列!!!

用动态规划做~

从前往后依次计算出当前递增子序列的值~dp[i]

最后找出最大的dp[i]就是答案~~

import java.util.Scanner;

/**
* @author 陈浩翔
*
* 2016-5-26
*/
public class Main{ public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
if(n==0){
break;
}
int a[]=new int[n];
int dp[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
dp[0]=a[0];
for(int i=1;i<n;i++){
int max=0;
for(int j=0;j<i;j++){
if(a[j]<a[i]&&dp[j]>max){
max=dp[j];
}
}
dp[i]=a[i]+max;
}
int max=dp[0];
for(int i=1;i<n;i++){
if(dp[i]>max){
max=dp[i];
}
}
System.out.println(max);
}
}
}

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)的更多相关文章

  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!(dp 最长上升子序列和)

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

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

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

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

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

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

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

  9. HDU 1087 Super Jumping! Jumping! Jumping! (DP)

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

随机推荐

  1. P1832 A+B Problem(再升级)

    P1832 A+B Problem(再升级) 题目提供者 usqwedf 传送门 标签 动态规划 数论(数学相关) 洛谷原创 难度 普及/提高- 通过/提交 107/202 题目背景 ·题目名称是吸引 ...

  2. 如何在windows上安装部署设置SVN服务器

    1   一.准备工作 1.SVN服务器:解压缩包,可以从官方网站下载最新版本. 2.SVN客户端:TortoiseSVN,即常说的小乌龟,是一个客户端程序,用来与服务器端通讯. 2 二.安装服务器和客 ...

  3. wampserver修改默认根目录

    1.打开wamp/scripts/config.inc.php ,修改$wwwDir = $c_installDir.’/www’; 2.打开wamp/bin/apache/apache2.4.9/c ...

  4. 服务器慢 mysql-bin.000001文件占满磁盘的原因与解决

    发现 VPS 服务器上的网站反应超级慢,简单的重启.重启各主要服务,发现mysql 的反应极其不正常. 一方面是问题,这与站点访问量有关.开始时从mysql 的配置文件 my.cnf 考虑,但志文工作 ...

  5. 编程书籍分享--pdf

    作为程序员,我觉得我们应该多学习.多思考.多分享. 今天就花费了一点时间把这几年搜集的编程资料上传到了网上做个分享, 其中涵盖.net .java.js.html5.css3.mysql.sqlser ...

  6. JDOM

    JDOM是什么: To provide a complete, Java-based solution for accessing, manipulating, and outputting XML ...

  7. 如何快速正确的安装 Ruby, Rails 运行环境-b

    对于新入门的开发者,如何安装 Ruby, Ruby Gems 和 Rails 的运行环境可能会是个问题,本页主要介绍如何用一条靠谱的路子快速安装 Ruby 开发环境.次安装方法同样适用于产品环境! 系 ...

  8. iOS开发者计划(转)

    苹果对软件和开发者的管理十分严格,你只有加入了Apple Developer计划之后,才能将你的软件放到真机上运行或者发布到App Store上去.这种方法看似麻烦,但是却有效的解决了盗版和劣质软件充 ...

  9. C++中二维数组的动态创建与处理

    C++中用new动态创建二维数组的格式一般是这样: TYPE (*p)[N] = new TYPE [][N]; 其中,TYPE是某种类型,N是二维数组的列数.采用这种格式,列数必须指出,而行数无需指 ...

  10. Word删除空白页

    1.常见的就是在前一页最后按delete 2.我遇到的问题是,共两页第一页是平常的A4,是表格,第二页也是A4,只不过横着显示(后来才知道的),中间是分节符,不能直接删除的,否则表格各个部分分开在好几 ...