Super jumping! jumping! jumping!

Source: Internet
Author: User

Super jumping! jumping! jumping!

Time limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other)

Total submission (s): 6 Accepted Submission (s): 5

Font:times New Roman |   Verdana | Georgia

Font size:←→

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 your 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

Test instructions: The problem is to find the sums of the largest ascending subsequence in the sequence. For example, the ascending sequence of 1 3 2 is: {1}{3}{2}{1,3}{1,2}. So the maximum is 1+3=4; defines two arrays: Num[i] The number of positions I position, sum[i] the maximum and of the position i is stored. State equation: Sum[i]=max {sum[j] (if (num[j]<num[i))} + Num[i], where j<i. The code takes care of dp[0] on the line. Code:

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace Std;
const int maxn=1002;
int NUM[MAXN];
int SUM[MAXN];
int n;

int main ()
{
while (scanf ("%d", &n)!=eof&&n)
{
for (int i=1;i<=n;i++)
scanf ("%d", &num[i]);
SUM[1]=NUM[1];
int ans=sum[1];
for (int i=2;i<=n;i++)
{
Sum[i]=num[i];
for (int j=1;j<i;j++)
{
if (Num[j]<num[i]&&sum[j]+num[i]>sum[i])//satisfies the current number of sum[j]+ in the increment and current sum[i] small front
Sum[i]=sum[j]+num[i];//sum[i] is the longest increment of the subsequence and, the current Num[i] is required.
}
if (Ans<sum[i])
Ans=sum[i];
}
printf ("%d\n", ans);

}
return 0;
}

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.