HDU 1087 super jumping! Jumping! Jumping!

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): 7997 accepted submission (s): 3210

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
 

#include<stdio.h>#include<string.h>#include<stdlib.h>int main( ){ int N; while(scanf("%d",&N)!=EOF,N) {   int i,j,t,A[10000],sum[10000];   memset(A,0,sizeof(A));   memset(sum,0,sizeof(sum));   for(i=1;i<=N;i++)   scanf("%d",&A[i]);   for(i=1;i<=N;i++)   sum[i]=A[i];   int flag=0;   for(i=2;i<=N;i++)
{         for(j=i-1;j>=1;j--)            {
        if(A[j]<A[i]&&!flag)                 {                  sum[i]+=sum[j];                  t=sum[i];                  flag=1;                  }
            else if(A[j]<A[i])                {                     t=sum[j]+A[i];                       if (sum[i]<t)                          sum[i]=t;                 }    
               }     flag=0;}      int res=sum[1];    for(i=2;i<=N;i++)    {        if(sum[i]>res)          res=sum[i];    }      printf("%d\n",res);    }  return 0;}
It is also a simple DP, which was made after the boss gave me a prompt .. Wrong answer at the start of submission... because this situation is not taken into account .. 7 6 4 5 7
Looking back, I found that this question was turned out to be a simulated question. Haha, It's too technical. This question is to find the maximum incremental sequence and of the given sequence, the real good practice is to find the state transition equation:
sum[i]=max{sum[j]}+a[i];
Find every sum [I] and find the maximum sum ..
   
#include<stdio.h>#include<string.h>#include<stdlib.h>int A[1010],sum[1010];int main( ){  int N;  while(scanf("%d",&N)!=EOF,N)  {   memset(sum,0,sizeof(sum));   int i,j,k,n=-1000,t;   for(i=0;i<N;i++)   scanf("%d",A+i);   sum[0]=A[0];   for(i=1;i<N;i++)   {     t=0;     for(j=0;j<i;j++)     if(A[j]<A[i]&&t<sum[j])     t=sum[j];     sum[i]=t+A[i];    if(sum[i]>n)     n=sum[i];  }  printf("%d\n",n);}return 0;}         

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.