# HDU 1087 Super jumping! jumping! jumping! (DP)

Source: Internet
Author: User

C-super jumping! jumping! jumping!Time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d & %i64u

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 24 1 2 3 44 3 3 2 10

Sample Output

4103 is the maximum ascending substring, can be discontinuous, but s[i] must be greater than s[i-1]. The idea is to calculate from the back, each with this position as the starting point of the largest ascending substring and find out, stored in the DP array. For example, only 1 2 99 97 98 of these three elements (and this is also a set of error-prone data), that is, starting from 98, 98 of the maximum ascending substring and obviously 98, so dp[4]=98. And start counting 97, The 97 algorithm is to find out what's behind it all bigger than it, then compare their DP values, take the largest one, plus 97 ., since only one 98,98 is greater than 97, so the DP value for this position is 97 + 98, that is, the ascending substring starting with 97 is 97 98. 99, then all the numbers are smaller than it is not advisable, so the DP value is it itself. Also count 2, obviously the back of all the numbers are bigger than it, so can be taken, but we want to take the maximum DP value that, that is, 97 (195), the same, 1 is the same, the last figure out 1 of the DP value is 198, the largest, take it. Generalize to the general situation, and then go through the DP array once the answer is calculated, because the final answer may not start with the first element.
`1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 #defineMAX 10055 6 intMainvoid)7 {8     intN;9     intS[max];Ten     intDp[max],max,ans;//Dp[i] is the same as the maximum ascending substring with the beginning of I One  A      while(SCANF ("%d", &n) &&N) -     { -          for(inti =0; i < N;i + +) thescanf"%d",&s[i]); -  -Ans = dp[n-1] = S[n-1]; -          for(inti = n-2; I >=0; I--)             +         { -Max =0; +              for(intj = i +1; J < N;j + +)//See S[i] which sub-string is s[i] can be added, find all such substrings, take the maximum DP value that A                 if(S[i] < s[j] && Max <Dp[j]) atMax =Dp[j]; -Dp[i] = S[i] +Max; -  -Ans = ans < dp[i]?Dp[i]: ans; -         } -Ans = ans <0?0: ans;//Note that you can jump from the start point directly to the end point, the value is 0, if the final value is a negative number, select this scheme in          -printf"%d\n", ans); to     } +  -     return    0; the}`

HDU 1087 Super jumping! jumping! jumping! (DP)

Related Keywords:

### Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.