HDU 1087 Super jumping! jumping! jumping! "DP"

Source: Internet
Author: User

Problem-solving ideas: The main idea of the topic is to give a list of the number of the longest increment of the number of columns and

Dp[i] Indicates the maximum of the arrival location I, then how to achieve I, then we can consider the absence of restrictions on the jump, that is, from the first, the---, i-1 locations jump to I,

And the topic is limited, the number of jumps to the point is greater than the point at which the jump starts.

So, the state transition equation is

for (i=1;i<=n;i++)
for (j=0;j<i;j++)

if (A[j]>a[i])
Dp[i]=max (Dp[j]+a[i],dp[i]);//Find the maximum value of the arrival location I

Reflection: Originally thought is that if given n points, then I add a point, then n+1 point into the end, then no matter how to jump, will reach the end, so dp[n+1] is the request

However, it is not written, and at the end of each time a DP value is calculated to compare the maximum value.

Super jumping! jumping! jumping!

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 23935 Accepted Submission (s): 10519

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 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 case are not-be-processed. outputfor each case, Prin T the maximum according to rules, and a line one case. sample INPUT3 1 3 2 4 1 2 3 4 4 3 3 2 1 0 sample Output 4 3 
#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int dp[1005],a[1005]; int main () {int n,i,j,maxx;while (scanf ("%d", &n)!=eof&&n) {memset (dp,0,sizeof (DP)); Maxx=dp[0];for (i=1;i <=n;i++) scanf ("%d", &a[i]), for (i=1;i<=n;i++) {for (j=0;j<i;j++) {Dp[i]=max ((Dp[j]+a[i]) * (A[i]>a[j] ), Dp[i]);      if (Dp[i]>maxx)      maxx=dp[i];}    } printf ("%d\n", Maxx);}}

  

HDU 1087 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.