Hdu1087 super jumping! Jumping! Jumping! [DP]

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): 22510 accepted submission (s): 9907

Problem descriptionnowadays, a kind of chess game called "super jumping! Jumping! Jumping !" Is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.



The game can be played by two or more than two players. it consists of a chessboard and some chessmen, and all chessmen are marked by a positive integer or "start" or "end ". the player starts from start-point and must jumps into end-point finally. in the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is 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 into SS unzip chessmen, and even you can straightly get to end-point from start-point. of course you get 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 is described in a line as follow:
N value_1 value_2... Value_n
It is guarantied that N is not more than 1000 and all value_ I are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
 
Outputfor 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
Question: The longest Ascending Order and.
import java.util.Scanner;public class Main{public static void main(String[] args){Scanner cin = new Scanner(System.in);final int maxn = 1002;int n, i, j, ans, tmp; int[] dp = new int[maxn], arr = new int[maxn];while(true){n = cin.nextInt();if(n == 0) break;ans = arr[0] = dp[0] = cin.nextInt();for(i = 1; i < n; ++i){arr[i] = dp[i] = cin.nextInt();for(j = 0; j < i; ++j)if(arr[i] > arr[j]) dp[i] = max(dp[i], dp[j] + arr[i]);if(dp[i] > ans) ans = dp[i];}System.out.println(ans);}}public static int max(int a, int b){return a > b ? a : b;}}


# Include <stdio. h> # define maxn 1002 // DP [I] indicates the maximum value of the sequence ending with I: int arr [maxn], DP [maxn]; int max (int A, int B) {return A> B? A: B;} int main () {int N, I, j, ans; while (scanf ("% d", & N), n) {for (I = 0; I <n; ++ I) scanf ("% d", arr + I); ans = DP [0] = max (0, arr [0]); for (I = 1; I <n; ++ I) {DP [I] = max (0, arr [I]); // attention for (j = 0; j <I; ++ J) if (ARR [J] <arr [I]) DP [I] = max (DP [I], DP [J] + arr [I]); If (DP [I]> ans) ans = DP [I];} printf ("% d \ n", ANS);} return 0 ;}


 

Hdu1087 super jumping! Jumping! Jumping! [DP]

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.