HDU1087 超级跳跃(递增子序列最大和)

Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36107    Accepted Submission(s): 16464


Problem Description
Nowadays, 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 across many 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.
 

Input
Input 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.
 

Output
For each case, print the maximum according to rules, and one line one case.
 

Sample Input
 
   
3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
 

Sample Output
 
   
4 10 3
 


分析:

现在,一种叫做“超级跳跃”的国际象棋游戏。跳跃!跳跃!“在二胺很受欢迎。”也许你是个好孩子,对这个游戏知之甚少,所以我现在向你介绍。

他的比赛可以由两个或两个以上的球员它由棋盘(棋盘)和一些棋子(棋子)组成,所有的棋子都标有一个正整数或“start”或“end”。玩家从起点开始,最后必须跳到终点.在跳跃过程中,玩家将访问路径中的棋子,但每个人都必须从一个棋子跳到另一个绝对更大(你可以假设起点是一个最小值和终点是最大值)。)。所有的球员都不能后退。一个跳跃可以从棋子跳到下一步,也可以穿过许多棋子,甚至你可以直线从起点到终点。当然你在这种情况下是零。一个球员是胜利者当且仅当他能根据他的跳跃方案获得更大的分数。请注意,您的得分来自您跳转路径中的棋子上的值之和。您的任务是根据给定的棋子列表输出最大值。

其实即使最长递增子序列和

公式为dp[[i]=max{dp[j[}+a[i];

#include
#include
int main()
{
    int n;

    int a[1000010],b[1000010],i,j,s;
    while(scanf("%d",&n)&&n!=0)
    {
        memset(b,0,sizeof(b));//b数组为递增序列到此的最大和
        for(i=1; i<=n; i++)
            scanf("%d",&a[i]);
        int k=-30000;//结果初始化为最小值,也有可能是负数
        for(i=1; i<=n; i++)
        {
            s=-30000;//初始化为最小值
            for(j=0; jk)
                k=b[i];
        }
        printf("%d\n",k);
    }
    return 0;
}

你可能感兴趣的:(模拟,动态规划)