Super jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 22479 accepted submission (s): 9890
Problem descriptionnowadays, 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 into SS unzip 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.
Inputinput 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.
Outputfor each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 24 1 2 3 44 3 2 10
Sample output
4103
Authorlcy meaning analysis: give a series of data, the first is the total number of chess pieces, followed by the number of each chess piece, the rule, the latter must be greater than the previous number of chess pieces, the solution is the sum of the pieces that pass through. The Code is as follows:
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; int A [10010], sum [10010]; // sum is used to store the sum of chess pieces, A [I] is used to store the int main () {int N, I; while (~ Scanf ("% d", & N), n) {memset (A, 0, sizeof (a); memset (sum, 0, sizeof (SUM )); for (I = 0; I <n; I ++) scanf ("% d", & A [I]); int temp, maxn =-1, J; // temp indicates the maximum value of the former each time. For (I = 0; I <n; I ++) {temp = 0; For (j = I-1; j> = 0; j --) {if (a [J] <A [I] & temp <sum [J]) temp = sum [J]; // temp is used to represent the maximum value of its I-1 values .} Sum [I] + = temp + A [I]; // the I-th value corresponds to the data of all the preceding data and maxn = max (maxn, sum [I]); // compare the maximum number of the remaining I-1 .} Printf ("% d \ n", maxn);} return 0 ;}
HDU 1087 super jumping! Jumping! Jumping! (DP two for loops, which are closer to the maximum value of its subcolumns)