http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super jumping! jumping! jumping!Time
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 1087
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
#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<algorithm>using namespacestd;#defineN 1000#defineOO 0x3f3f3f3fintMain () {intN, A[n], sum[n]; while(SCANF ("%d", &N), N) {intI, J; Memset (A,0,sizeof(a)); memset (SUM,0,sizeof(sum)); for(i=1; i<=n; i++) scanf ("%d", &A[i]); /** I decided to learn DP This write nature is to own sentiment, I think really not easy, although written, although very simple, I am just helpless, do not think I opened the number group sum[], the record is from 1 to i the largest rise sequence and since Sum[i] record is the largest from 1 To the value of I, then each comparison a[i] and a[j] size if a[i] larger than a[j], you need to choose Sum[i] and Sum[j]+a[i] The maximum value finally in sum to choose the maximum is OK!!! **/ for(i=1; i<=n; i++) {Sum[i]=A[i]; for(j=1; j<=i; J + +) { if(a[i]>A[j]) sum[i]= Max (Sum[i], a[i]+Sum[j]); } } intMax =-Oo; for(i=1; i<=n; i++) Max=Max (max, sum[i]); printf ("%d\n", Max); } return 0;}
View Code
(Max ascending subsequence) Super jumping! jumping! jumping! --HDU--1087