Super jumping! jumping! jumping!

Source: Internet
Author: User
Tags define local

Super jumping! jumping! jumping! Problem descriptionnowadays, 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. Inputinput 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. Outputfor, print the maximum according to rules, and one line one case. Sample INPUT3 1 3 2
4 1 2) 3 4
4 3 3) 2 1
0 Sample Output4
10
3 answer This topic giant pits, which is the largest subsequence and (unclear how to say, look at the data), rather than the eldest of the sequence and (or the longest does not drop the substring), so a start with greed to try, hang up.
Test data: 101545 41 54548544 4545545444, the answer is 6628 (the sum of blue).
#include <cstdio>#include<iostream>#include<sstream>#include<string>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<vector>#definePI ACOs (-1.0)#defineMS (a) memset (A,0,sizeof (a))#defineMSP Memset (Mp,0,sizeof (MP))#defineMSV memset (vis,0,sizeof (VIS))#defineMSD memset (Dp,0,sizeof (DP))using namespacestd;//#define LOCALintdp[1001];inta[1001];intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin); //freopen ("OUT.txt", "w", stdout);#endif //LOCALIos::sync_with_stdio (false); intN;  while(cin>>n&&N) {msd,ms (a);  for(intI=1; i<=n; i++) Cin>>A[i];  for(intI=1; i<=n; i++)        {            intans=-999999999;  for(intj=0; j<i; J + +)            {                if(a[i]>A[j]) ans=Max (ans,dp[j]); } Dp[i]=ans+A[i]; }        intans=-999999999;  for(intI=0; i<=n;i++) ans=Max (ans,dp[i]); printf ("%d\n", ans); }    return 0;}
View Code

Super jumping! jumping! jumping!

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.