Super Jumping! Jumping! Jumping!

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
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
这道题的实质就是求一个递增序列,使得组成该序列的所有元素的和最大,输出和即可。
解题思路:判断i点元素和前面元素能否构成递增序列,如果能,则求出该序列在i点的和;若不能,则把a[i]作为i点的和。最后求出最大的和即可。
AC代码:
#include<stdio.h>
int a[1005],sum[1005];
int main()
{
    int n,i,j;
    while(scanf("%d",&n)&&n)
    {
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        int max=sum[0]=a[0]; //定义a[0]为最大值
        for(i=1;i<n;i++)
         {
          sum[i]=a[i];// 先把它自己作为序列在i点的和
          for(j=0;j<i;j++)
            if(a[i]>a[j]&&sum[j]+a[i]>sum[i])
            //如果序列是递增的,且前面比它小的元素组成的递增序列的和加上它自己,大于它自己
              sum[i]=a[i]+sum[j];//把二者的和作为递增序列在i点的和
            if(sum[i]>max)  //如果递增序列在i点的和大于最大值
            max=sum[i]; //把在i点的和作为最大值
         }
        printf("%d\n",max);
    }
    return 0;
}

hdu 1087 Super Jumping! Jumping! Jumping! 动态规划相关推荐

  1. HDU 1087 [Super Jumping! Jumping! Jumping!]动态规划

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意:有N个格子,每个格子有数值.从原点开始跳,可以跳到任何一个位置:在某一个位置,只能跳到 ...

  2. hdu 1087 Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular i ...

  3. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  4. hdu 1087 Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular i ...

  5. HDU 1087 Super Jumping! Jumping! Jumping!【最大递增子段和】

    Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!&quo ...

  6. 最长上升子序列模板 hdu 1087 Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular i ...

  7. hdu - 1087 - Super Jumping! Jumping! Jumping!

    题意:求最大升序和. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 -->>设d[i]表示以第i个数为终点的最大升序和,然后从第1 ...

  8. HDU 1087 Super Jumping! Jumping! Jumping! (最长上升子序列的变形,子序列值最大)

    题意 wsw获得了与小姐姐约会的机会,同时也不用担心wls会发现了,可是如何选择和哪些小姐姐约会呢?wsw希望自己可以循序渐进,同时希望挑战自己的极限,我们假定每个小姐姐有一个"攻略难度值& ...

  9. 动态规划训练17 [Super Jumping! Jumping! Jumping! HDU - 1087 ]

    Super Jumping! Jumping! Jumping! HDU - 1087 过于简单懒得说了 #include <cstdio> #include <algorithm& ...

最新文章

  1. 【百度地图API】如何制作班级地理通讯录?LBS通讯录
  2. go微服务框架go-micro深度学习(一) 整体架构介绍
  3. linux系统关于ping的命令,详解Linux系统中ping和arping命令的用法
  4. 不同包下,相同数据结构的两个类进行转换
  5. Spark rdd 介绍,和案例介绍
  6. JavaScript高级程序设计学习(六)之设计模式
  7. What means the error-message 'java.lang.OutOfMemoryError: GC overhead limit exceeded' in Java?
  8. ad用户和计算机无法启动,windows 2008AD计算机启动脚本无法执行
  9. android studio 分页,Android Paging codelab
  10. 静态路由的设置以及缺省路由的发布
  11. Oracle笔记(九) 表的创建及管理
  12. 11. Django基础:应用及分布式路由
  13. python语言用什么编译器_如何修改python语言pycharm工具的默认编译器
  14. 【论文解读】VDN( Variational Denoising Network )变分去噪网络
  15. h264js解码直播解码显示
  16. Canal Admin Web-UI 学习
  17. 公众号如何获得关注粉丝openid?
  18. OGG REPA进程 Error ORA-01031报错处理
  19. Python调用WPS进行文档转换PDF及PDF转图片
  20. 计算机毕业设计不会做?

热门文章

  1. map和hasmap的区别
  2. Ubuntu 10.04下SSH配置
  3. 生产环境子域降级记录
  4. JavaScript 设计模式 : 巧用'工厂模式'和'创建者'模式
  5. How to change in the Cocos2d-x project from landscape to portrait both in iOS and Android
  6. Windows phone 8 学习笔记(7) 设备(转)
  7. python 调试命令
  8. Spring3 集成 Hibernate3
  9. Centos 5.5下面架设NTP服务器
  10. Work Measurement - 1