Super jumping! jumping! jumping!
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 19979 Accepted Submission (s): 8670
Problem Description Nowadays, a kind of chess game called "Super jumping! jumping! Jumping! "is very popular in HDU. Maybe you is a good boy, and know little about the this game, so I introduce it to you now.
The game can be played by and more than the players. It consists of a chessboard (chessboard) and some chessmen (chess pieces), and all chessmen is marked by a positive integer or "start" or "End ”. The player starts from start-point and must jumps to end-point finally. In the course of jumping, the player would visit the chessmen in the path, but everyone must jumps from one Chessman to Ano Ther absolutely bigger (you can assume start-point are 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 can straightly get to end-point From Start-point. Of course you get the 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 was described in a line as follow:
N value_1 value_2 ... value_n
It is guarantied, that N was not more than, and all value_i be in the range of 32-int.
A test case, starting with 0 terminates, the input and this test are not 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
Recommend We have carefully selected several similar problems for you:1176 1159 2084 1231 1421
Dynamic programming Classic problem, test instructions is to find an increment sequence to make it and maximum (discontinuous)
Left-to-right processing, the term I is judged whether each item before it is less than the current item, if less than the description a[i] can be used as an increment of the sequence of items, then only need to determine the a[i] join the current sequence and whether the increase
Finally, simply remove the maximum value from the DP array
The code is as follows:
#include <map>
#include <cmath>
#include <vector>
#include <string>
# Include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ESP 1e-9
#define MAXN 1010
#define LL Long long
#define INF 0x7FFFFFFF
#define SW (A, b) a^=b;b^=a;a^=b;
#define REP (i,j,k) for (int i=j, i<k; ++i)
#define REP (i,j,k) for (int i=j; i<=k; ++i)
using namespace std;< C16/>int A[MAXN];
int DP[MAXN];
int main (void) {
int n;
while (scanf ("%d", &n), N) {
rep (i, 0, n) {
scanf ("%d", &a[i]);
}
Dp[0] = a[0];
int max = a[0];
Rep (i, 1, n) {
dp[i] = a[i];
Rep (j, 0, i) {
if (A[i] > A[j]) {//= take the number of items in front of item I earlier than A[i]
if (Dp[i] < dp[j]+a[i])
dp[i] = dp[j]+a[i];
}
}
if (Dp[i] > Max)
max = Dp[i];
}
cout << Max << Endl;
}
return 0;
}