HDU 1087 Super Jumping! Jumping! Jumping!
2015-08-12 12:43
309 查看
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
3
题意:从任意起点向前跳,要求跳的下一地点的值必大于当前起所在的值。求起点到终点所跳的路径值的最大和。
思路:DAG的动态规划 (记忆化搜索+dp )
设max_i[] 为从第i个点为起点的最大和。
for j <- i to n
max_i[i] = max( max_i[i], dp(j)+ road[j]) ;
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 ; }
相关文章推荐
- php新手常用的函数(随时更新)
- HDOJ 5379 Mahjong tree 树形DP
- ASP.NET 成功执行Update 的 ExecuteNonQuery() 返回值大于0,但是查看数据库却没有改变
- Mysql注入总结(三)
- HDU 3371 Connect the Cities (克鲁斯卡尔)
- HDU 5374 Tetris
- 绿色线程
- This Activity already has an action bar supplied by the window decor
- PHP SOAP 发送XML
- linux下提示一些基本的命令找不到
- rest接口调用
- C++非循环链表的初始化和反转(指针操作)
- listView item进行更新
- axure团队合作开发原型图
- [leetcode-123]Best Time to Buy and Sell Stock III(c++)
- 欢迎使用CSDN-markdown编辑器
- 数组中出现次数超过一半的数字
- Understanding the STM32F0's GPIO
- Flume 1.5日志收集和存款mongodb安装结构
- nyoj92图像有用区域【bfs】