杭电1087--Super Jumping! Jumping…

来源:互联网 发布:数据采集卡原理设计 编辑:程序博客网 时间:2024/06/02 04:18
Nowadays, a kind of chess game called “Super Jumping! Jumping!Jumping!” is very popular in HDU. Maybe you are a good boy, andknow little about this game, so I introduce it to you now.

杭电1087--Super <wbr>Jumping! <wbr>Jumping! <wbr>Jumping!


The game can be played by two or more than two players. It consistsof a chessboard(棋盘)and some chessmen(棋子), and all chessmen aremarked by a positive integer or “start” or “end”. The player startsfrom start-point and must jumps into end-point finally. In thecourse of jumping, the player will visit the chessmen in the path,but everyone must jumps from one chessman to another absolutelybigger (you can assume start-point is a minimum and end-point is amaximum.). And all players cannot go backwards. One jumping can gofrom a chessman to next, also can go across many chessmen, and evenyou can straightly get to end-point from start-point. Of course youget zero point in this situation. A player is a winner if and onlyif he can get a bigger score according to his jumping solution.Note that your score comes from the sum of value on the chessmen inyou jumping path.
Your task is to output the maximum value according to the givenchessmen list.
Input
Input contains multiple test cases. Each test case isdescribed 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 arein the range of 32-int.
A test case starting with 0 terminates the input and this test caseis not to be processed.
Output
For each case, print the maximum according to rules, and oneline one case.
Sample Input
3 1 3 2 4 12 3 4 4 3 3 2 1 0
SampleOutput
4 103
# include<stdio.h>
int main()
{
    int i,n,j,max,a[1024],sum[1024];
    while(scanf("%d",&n),n!=0)
    {
        a[0]=sum[0]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum[i]=a[i];
        }
        for(i=1;i<=n;i++)
        {
            max=0;
            for(j=0;j<i;j++)
                if(a[j]<a[i]&&max<sum[j])
                    max=sum[j];
            sum[i]=max+a[i];
        }
        max=0;
        for(i=1;i<=n;i++)
        {
            if(max<sum[i])
                max=sum[i];
        }
            printf("%d\n",max);
    }
    return 0;
}
 
 

 

0 0
原创粉丝点击