HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)
2017-04-09 19:59
155 查看
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 36967 Accepted Submission(s): 16873
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
Author
lcy
#include<stdio.h> #include<cstring> #include<iostream> using namespace std; int main() { int i, sum[1000],a[1000],n,j; while(cin>>n&&n) { for(i = 1; i <= n; i++) { cin>>a[i]; sum[i] = 0; } for(i = 1; i <= n; i++) { int flag = 0; for(j = i - 1; j >= 1; j--) { if(a[i] > a[j] && flag < sum[j]) { flag = sum[j]; } } sum[i] = a[i] + flag; } int Max = sum[1]; for(i = 2; i <= n; i++) { if(Max < sum[i]) { Max = sum[i]; } } cout<<Max<<endl; } return 0; }
思路:首先第一个for遍历1-n,这个时候先设一个flag=0然后在遍历从1到i,因为题目求得是单调最长序列的和所以j每次都要在i前面,然后在满足啊a[i]>a[j]的情况下用flag记下j前面序列和的最大值,在遍历完j后此时flag存储了1-j中最大的sum和,此时,只要一步把a[i]加上,就可以表示sum[i]的总和。。。。所以最后只要判断sum序列中,最大的值就可以。。。。
相关文章推荐
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping! (求最大上升子序列和,动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)
- hdoj 1087 Super Jumping! Jumping! Jumping!(动态规划)
- hdu 1087 Super Jumping! Jumping! Jumping! (动态规划,求最长子序列之和)
- Super Jumping! Jumping! Jumping!---hdu1087(动态规划)
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
- G - Super Jumping! Jumping! Jumping!(动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)
- 【HDU 1087】Super Jumping! Jumping! Jumping!(最大上升子序列和,动态规划)
- hdu1087Super Jumping! Jumping! Jumping!【动态规划】
- HDOJ 题目1087Super Jumping! Jumping! Jumping!(动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping! 动态规划
- 【HDU 1087】Super Jumping! Jumping! Jumping! (dp动态规划)
- Super Jumping! Jumping! Jumping!(动态规划)
- hdu 1087 Super Jumping! Jumping! Jumping! 动态规划
- hdu 1087 Super Jumping! Jumping! Jumping! 动态规划
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划)
- hdu1087 Super Jumping! Jumping! Jumping!(简单动态规划)
- 动态规划—杭电1087 Super Jumping! Jumping! Jumping!