[背包问题][第三阶段-初见dp][HDU-1087]Super Jumping! Jumping! Jumping!
来源:互联网 发布:微信刷步软件 编辑:程序博客网 时间:2024/05/29 17:33
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.
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.
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 24 1 2 3 44 3 3 2 10
Sample Output
4103
import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner in = new Scanner(System.in);int n = in.nextInt();while(n!=0){int[] num = new int[n+1];num[0]=-1;int i,j;for(i=1;i<=n;i++)num[i]=in.nextInt();int[] dp = new int[n+1];dp[0]=-1;int M=num[1];for(i=1;i<=n;i++){int max= num[0];for(j=0;j<i;j++){if(max<dp[j])max=dp[j];}if(max==-1)dp[i]=num[i];else if(M<num[i]){dp[i]=num[i]+max;M=i;}else {dp[i]=max;}}System.out.println(dp[n]);n = in.nextInt();}}}
0 0
- [背包问题][第三阶段-初见dp][HDU-1087]Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping! DP
- HDU 1087 Super Jumping! Jumping! Jumping! DP
- hdu 1087 Super Jumping! Jumping! Jumping! ----dp
- HDU 1087 Super Jumping! Jumping! Jumping!(dp)
- Super Jumping! Jumping! Jumping! -HDU 1087 dp
- HDU 1087 Super Jumping! Jumping! Jumping!(DP)
- HDU 1087 Super Jumping! Jumping! Jumping! DP
- HDU 1087 Super Jumping! Jumping! Jumping!(DP)
- HDU 1087 Super Jumping! Jumping! Jumping!(DP)
- [HDU 1087 Super Jumping! Jumping! Jumping!] DP
- DP-HDU-1087-Super Jumping!Jumping!Jumping!
- HDU-1087-DP-Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!(DP)
- hdu 1087 Super Jumping! Jumping! Jumping! dp
- HDU 1087 Super Jumping! Jumping! Jumping! DP
- HDU 1087 Super Jumping! Jumping! Jumping!【dp】
- HDU-1087 Super Jumping! Jumping! Jumping! (DP)
- Linux学习笔记之基本命令二(目录和文件)
- Java 实现把异常信息写入到文件中
- RelativeLayout介绍
- java web项目上有红色叉,文件没有报错,怎么解决?
- Boost your productivity: Cripple your technology
- [背包问题][第三阶段-初见dp][HDU-1087]Super Jumping! Jumping! Jumping!
- 100. Same Tree Leetcode Python
- 消息传递函数
- 咨钻锥纂妆族谆卓佐昨作赘字最淄邹资专
- 遵籽姿注自钻谞总状桌赘仔昨租爪籽罪驻
- php-fpm经常出现502解决方法
- 蹂躏D&F数据之XP-NtOpenProcess(虚拟机)
- sql语句百例之Oracle
- 走赘赘篆住准茁赘渍抓住抓琢资族祝左综