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: ...
随机推荐
- UVA 10739 String to Palindrome(动态规划 回文)
String to Palindrome 题目大意:给出一个字符串s,现在可以进行3种操作(添加字母,删除字母,替换字母),将其变成回文串,求出最少的操作次数.比如abccda,可以用删除操作,删除b ...
- stringstream vs sprintf, sscanf.
前言 以前一直认为 stringstream 远不如 sprintf. 近日突然萌发了看看 stirngstream 是不是真的如我想的那么烂 对比 // stringstream. stringst ...
- Dynamic Programming: From novice to advanced
作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...
- phpstorm使用技巧
确实很好用,不过还是要看一些方法 转自:http://blog.sina.com.cn/s/blog_488193d70102vk7e.html 2, 关联DOC文档: 右键External Libr ...
- github 查看单个文件的历史记录命令
gitk 安装: apt-get install gitk 点击打开链接http://stackoverflow.com/questions/278192/view-the-change-histor ...
- tmux与vim主题不一致
在centos6.5 x64 vim6.2 需要在tmux.conf中添加set -g default-terminal "screen-256color" 然后再次启动tmux的 ...
- jQuery实现购物车多物品数量的加减+总价+删除计算
<?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- PHP5.5安装php-redis扩展
windows下开发用的xampp集成的环境,想装个php-redis扩展,扩展的github地址: https://github.com/nicolasff/phpredis 描述里找到window ...
- 将 Wing IDE 与 Maya 结合使用(摘自Maya用户指南)
1. 将 wingdbstub.py 从 Wing IDE 安装目录复制到 Maya Python 脚本路径. 2. 确保已在“Wing IDE > 编辑 > 首选项 > 调试器”中 ...
- Aspose.Cells 导入导出EXCEL(转)
Aspose.Cells 导入导出EXCEL 修改样式 Workbook workbook = new Workbook(); //工作簿 Worksheet ...