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
 

题意:其实就是最大递增子段和

思路:状态方程:sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j,a[i]<a[j]

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a[1005],dp[1005];
const int inf = 999999999; int main()
{
int n,i,t,m,j,ans;
while(~scanf("%d",&n),n)
{
memset(dp,0,sizeof(dp));
for(i = 1;i<=n;i++)
scanf("%d",&a[i]);
for(i = 1;i<=n;i++)
{
ans = -inf;
for(j = 0;j<i;j++)
{
if(a[i]>a[j])
ans = max(ans,dp[j]);
}
dp[i] = ans+a[i];
}
ans = -inf;
for(i = 0;i<=n;i++)
{
if(dp[i]>ans)
ans = dp[i];
}
printf("%d\n",ans);
} return 0;
}

HDU1087:Super Jumping! Jumping! Jumping!(DP)的更多相关文章

  1. HDU1087 Super Jumping! Jumping! Jumping! —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limi ...

  2. 【HDU - 1087 】Super Jumping! Jumping! Jumping! (简单dp)

    Super Jumping! Jumping! Jumping! 搬中文ing Descriptions: wsw成功的在zzq的帮助下获得了与小姐姐约会的机会,同时也不用担心wls会发现了,可是如何 ...

  3. hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  4. 解题报告 HDU1087 Super Jumping! Jumping! Jumping!

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...

  6. HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. 杭电1087 Super Jumping! Jumping! Jumping!(初见DP)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意: 求递增子序列最大和 思路: 直接dp就可以求解,dp[i]表示以第i位结尾的递增子 ...

随机推荐

  1. Eclipse用法和技巧十七:覆盖父类方法

    在学校里面学习java,遇到访问权限修饰符一直停留在public是公有的,外面可以访问:protected是对子类可见的,外部不可以访问:private仅在本类中可见.工作之后,接触到了java代码多 ...

  2. 在C++工程中main函数之前跑代码的廉价方法(使用全局变量和全局函数)

    // test.cpp : Defines the entry point for the console application. // #include "stdafx.h" ...

  3. Codility上的问题 (16) Omicron 2012

    比较无聊的题,求斐波那契数的第N^M项. f(0) = 0, f(1) = 1, f(n) = f(n - 1) + f(n - 2),结果对10000103取模. N, M在[0..10^7]之间. ...

  4. MySql自己定义排序

    查询语句: select id,name,stauts from special where id in (50,51,52,53,54,55) order by FIELD( id ,51,50, ...

  5. 控件编写:增强 TMEMO (一)(增加对WM_HSCROLL消息的处理)

    相信没有什么人对 MEMO 陌生了吧.尽管其组件的功能不错.但是,对它进行一些功能的改进,可以更好的使用. 有的时候,我们想要知道,当前的坐标是什么?甚至,想要在 滚动条滚动时触发一些事件. 但,TM ...

  6. JQuery+AJAX实现搜索文本框的输入提示功能

    平时使用谷歌搜索的时候发现只要在文本框里输入部分单词或字母,下面马上会弹出一个相关信息的内容框可供选择.感觉这个功能有较好的用户体验,所以也想在自己的网站上加上这种输入提示框. 实现的原理其实很简单, ...

  7. 使用apache daemon让java程序在unix系统上以服务方式运行

    通过使用apache_commons_daemon,可以让Java程序在unix系统上以服务器的方式运行. 当然,通过wrapper也是可以达到这样的目的,wrapper还可以指定java应用中用到的 ...

  8. Java反射库中的安全漏洞在30个月后终于修复了(转)

    2013年7月,安全组织Security Explorations发现了Java 7u25中的一个安全漏洞,通过这个漏洞攻击者可以完全摆脱Java沙箱.Oracle在更新的7u40中包含了一个补丁,但 ...

  9. CentOS6.4 编译安装Python 3.3.2 - CRPER木木

    基础环境: CentOS6.4(预装GCC,或者联网YUM---GCC编译写进这里太臃肿,找机会另外写一篇) Python 3.3.2     下载链接: http://www.python.org/ ...

  10. DMP文件的生成和使用

    1.生成dmp的程序 #include  <dbghelp.h> #pragma comment(lib,  "dbghelp.lib") //设置异常处理回调函数Se ...