HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)
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~)的更多相关文章
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1087 Super Jumping! Jumping! Jumping! (DP)
C - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
随机推荐
- Codevs 2597 团伙(并查集)
2597 团伙 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么 ...
- RD / RMDIR Command
Quote from: http://ss64.com/nt/rd.html RD Delete folder(s) Syntax RD pathname RD /S pathname RD /S / ...
- Python没有执行__init__
疑惑 提出问题 前天同事问我一个问题,为什么这个脚本中的没有调用A 的__init__.脚本如下: class A(object): def __init__(self, *args, **kwarg ...
- PhoneGap与WAP站静态化
最近在参与的WAP站项目,决定将所有页面都静态化处理,登录验证.价格数据等都通ajax动态的方式实现.开始这么规划的目前是为了页面提高网站加载速度及SEO,最近看到了一篇报道phonegap buil ...
- 提高C#编程水平不可不读的50个要诀
提高C#编程水平的50个要点 1.总是用属性 (Property) 来代替可访问的数据成员 2.在 readonly 和 const 之间,优先使用 readonly 3.在 as 和 强制类型转换之 ...
- 【转】JavaScript闭包
摘自:JavaScript作用域闭包简述 使用外部变量的函数就是闭包,闭包可以给我们带来一些便利,就是可以在高等级的作用域使用低等级作用域中的变量: 例: var data = []; fun ...
- 微信公众号-加解密数据demo坑
demo里面的MsgSignature作为url参数一部分了,demo也不更新下 坑爹的微信! 解密信息部分 include_once "wxBizMsgCrypt.php"; $ ...
- Uploadify 上传失败
更改Apache的php.ini的配置 In my php.ini (created custom ini file in public_html) would this solve this pro ...
- Linux下find指令
Linux是一个“一切皆文件”的操作系统,find(查找文件)指令就尤为重要了.find命令在目录结构中搜索文件,并执行指定的操作. 1.命令格式: find pathname -options [- ...
- Visual C++ 6.0常用快捷键
一.常用编译相关的快捷键 1.编译(单个文件) Ctrl+F7 2.连接 F7 3.运行 Ctrl+F5 二.常用调试相关的快捷键 1.GO(全速运行) F5 2.Stop Debuging(停 ...