hdu1087(最长上升子序列求和)

来源:互联网 发布:王者荣耀引流源码 编辑:程序博客网 时间:2024/05/16 23:38

http://acm.hdu.edu.cn/showproblem.php?pid=1087

Super Jumping! Jumping! Jumping!

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


Problem Description
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.

hdu1087(最长上升子序列求和)


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 32
 
4 1 2 34
4 3 3 21
0


 

Sample Output
 
4
10
3


 

Author
lcy
题意:求一个数列的最大连续子序列的和。
可以参考hdu最大拦截系统。。
动态方程:不难知道整体最优解与局部最优解的关系为:dp[i]=max{dp[j]+1}}(0<j=<i)
 
 
#include<stdio.h>
#include<string.h>
int a[10010],b[10010];
int main()
{
    inti,j,n;
   while(scanf("%d",&n)!=EOF)
    {
  if(n==0)
   break;
       memset(b,0,sizeof(b));
       for(i=0;i<n;i++)
           scanf("%d",&a[i]);
       b[0]=a[0];
       int maxn;
       for(i=1;i<n;i++)
       {
           b[i]=a[i];
           for(j=0;j<i;j++)
               if(a[i]>a[j]&&b[j]+a[i]>b[i])
               {
                   b[i]=b[j]+a[i];
               }
               //if(b[i]>maxn)
                //   maxn=b[i];
       }
  maxn=a[0];
       for(i=1;i<n;i++)
       {
           if(maxn<b[i])
           {
               maxn=b[i];
           }
       }
       printf("%d\n",maxn);
    }
    return0;
}
 
 
原创粉丝点击