HDU 1087 Super Jumping! Jumping! Jumping!
来源:互联网 发布:2017学php好找工作吗 编辑:程序博客网 时间:2024/06/06 04:51
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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
题意:从任意起点向前跳,要求跳的下一地点的值必大于当前起所在的值。求起点到终点所跳的路径值的最大和。
思路:DAG的动态规划 (记忆化搜索+dp )
设max_i[] 为从第i个点为起点的最大和。
for j <- i to n
max_i[i] = max( max_i[i], dp(j)+ road[j]) ;
#include <iostream>#include <cstdio>#include <cstring>#define max(a,b) (a>b?a:b)using namespace std;const int maxn = 1000 + 100 ;int n ;int a[maxn] ;int temp1[maxn] ;int dp( int num) { int& ans = temp1[num] ; if( ans > 0 ) { return ans ; } for( int i = num ; i < n ; ++i ) { if( a[i] > a[num] ) { ans = max( dp(i) + a[i] , ans ) ; } } return ans ;}int main() { while(~scanf("%d",&n),n) { memset(temp1 , 0 , sizeof( temp1)) ; for( int i = 0 ; i < n ; ++i ) { scanf("%d",&a[i]) ; } int maxx = -1 ,temp ; for( int i = 0 ; i < n ; ++i ) { if( (temp = dp(i) + a[i]) > maxx ) { maxx = temp ; } } printf("%d\n",maxx) ; } return 0 ;}
0 0
- hdu/hdoj 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- Hdu 1087 - Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- Hdu 1087 Super Jumping! Jumping! Jumping!
- hdu - 1087 - Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping! DP
- OC学习笔记六 内存管理(autorelease)
- android Handler 基础知识入门
- 收录最全的NGUI示例&文档中文教程
- 深度学习自学笔记(一)
- ISE MicroBlaze GPIO输入输出测试总结
- HDU 1087 Super Jumping! Jumping! Jumping!
- RPC远程调用概念 && demo实例
- UE4 Particle Emitter Technical Guide
- rootfs做好之后需要动静态链接库
- Unity NGUI UIKeyBinding
- UE4 Particle Module Technical Guide
- nyoj92图像有用区域【bfs】
- 微博输入框插件
- IE6、7、8中css给span加float:right右浮动后内容换行下移