HDU1087 Super jumping! jumping! jumping! Maximum continuous increment sub-segment

Source: Internet
Author: User

Super jumping! jumping! jumping!

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 32561 Accepted Submission (s): 14689

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(chess board)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 was guarantied that N was not more than 1000 And all value_i is 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

1#include <iostream>2#include <string.h>3 using namespacestd;4 intdp[1111];5 intn,temp;6 inta[1111];7 //Dp[j] = max{dp[i]}+temp;8 intMain ()9 {Ten      while(cin>>n,n) { One          for(intI=0; i<n;i++) ACin>>A[i]; -Memset (DP,0,sizeof(DP)); -dp[0]=a[0]; the  -          for(intI=1; i<n;i++){ -temp=0; -              for(intj=0; j<i;j++){ +                  if(a[i]>A[j]) { -temp =Max (temp,dp[j]); +  A                  } at             } -Dp[i] = A[i] +temp; -         } -temp=-1; -          for(intI=0; i<n;i++){ -             if(temp<Dp[i]) intemp=Dp[i]; -         } tocout<<temp<<Endl; +     } -     return 0; the}

HDU1087 Super jumping! jumping! jumping! Maximum continuous increment sub-segment

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.