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.

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

OutputFor 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这条路上有多个棋手,每个棋手都有一个价值,如果你想获得某个棋手的价值则该棋手的价值必须比上一个获得的棋手的价值大,求在这条路线上你能获得的最大价值
分析:从题面上来看,是让我们求最大递增子序列的和。如果我们要求前k项max(lIs),那我们可以从前k项遍历,如果str[j]<str[k],则dp[k]=max(dp[k],dp[j]+str[k]),反之我们不更新。
dp[i]表示前i项最大递增子序列的和
 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<iostream>
#include<map>
#include<vector>
#define Inf 0x3f3f3f3f
#define PI acos(-1.0)
using namespace std;
int dp[];
int str[];
int main()
{
int m,n,i,j,pos;
while(scanf("%d",&m)!=-&&m)
{
for(i=; i<=m; i++)
{
scanf("%d",&str[i]);
}
memset(dp,,sizeof(dp));
int ans=-Inf;
for(i=;i<=m;i++)
{
dp[i]=str[i];
for(j=;j<=i;j++)
{
if(str[j]<str[i])
{
dp[i]=max(dp[i],dp[j]+str[i]);
}
}
ans=max(ans,dp[i]); }
cout<<ans<<endl;
}
return ;
}
我们会发现对与前n项的max(LIS),都有这个重叠子问题,因此
我们构造状态转移方程dp[k]=max(dp[k],dp[j]+str[k])

Super Jumping! Jumping! Jumping(最大递增子序列的和)的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列

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

  2. HDU 1087 简单dp,求递增子序列使和最大

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

  3. (转载)最长递增子序列 O(NlogN)算法

    原博文:传送门 最长递增子序列(Longest Increasing Subsequence) 下面我们简记为 LIS. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则 ...

  4. nyoj17_又做最大递增子序列

    单调递增最长子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 求一个字符串的最长递增子序列的长度 如:dabdbf最长递增子序列就是abdf,长度为4   输入 ...

  5. 最长公共子序列(LCS)和最长递增子序列(LIS)的求解

    一.最长公共子序列 经典的动态规划问题,大概的陈述如下: 给定两个序列a1,a2,a3,a4,a5,a6......和b1,b2,b3,b4,b5,b6.......,要求这样的序列使得c同时是这两个 ...

  6. 最长递增子序列 O(NlogN)算法

    转自:点击打开链接 最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS. 排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个 ...

  7. [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列

    Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...

  8. 51nod 1134 最长递增子序列

    题目链接:51nod 1134 最长递增子序列 #include<cstdio> #include<cstring> #include<algorithm> usi ...

  9. 动态规划 - 最长递增子序列(LIS)

    最长递增子序列是动态规划中经典的问题,详细如下: 在一个已知的序列{a1,a2,...,an}中,取出若干数组组成新的序列{ai1,ai2,...,aim},其中下标i1,i2,...,im保持递增, ...

随机推荐

  1. 条款5.了解c++默默编写并且调用了哪些函数。

    如果想在一个内含reference成员的class内支持赋值操作,必须自己定义copy assignment操作符.而且面对“内含有const成员的”class,编译器的反应也是相同的,由于更改con ...

  2. React 实现 Table 的思考

    琼玖 1 年前 (写的零零散散, 包括github不怎么样) Table 是最常用展示数据的方式之一,可是一个产品中往往很多非常类似的 Table, 但是我们碰到的情况往往是 Table A 要排序, ...

  3. C#当中利用Attribute实现简易AOP

    首先看一段简单的代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } //来自UI层的调用 ...

  4. BAT级别对照表

  5. Android Volley的基本用法

    1. Volley简介 我们平时在开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进行H ...

  6. 激活函数之ReLU/softplus介绍及C++实现

    softplus函数(softplus function):ζ(x)=ln(1+exp(x)). softplus函数可以用来产生正态分布的β和σ参数,因为它的范围是(0,∞).当处理包含sigmoi ...

  7. Linux 工具套件 —— binutils、readelf

    readelf:Linux 下专门针对 ELF 文件格式的解析器: 0. binutils GNU Binutils gnu binutils 一套二进制工具的集合,主要包含:ld(gnu linke ...

  8. Hibernate中 一 二级缓存及查询缓存(1)

    最近趁有空学习了一下Hibernate的缓存,其包括一级缓存,二级缓存和查询缓存(有些是参照网络资源的): 一.一级缓存     一级缓存的生命周期和session的生命周期一致,当前sessioin ...

  9. hibernate正向工程生成数据库

    hibernate正向工程生成数据库 hibernate.cfg.xml ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...

  10. YII框架安装过程-数据库访问

    1.电脑上原来安装了phpstudy.关掉phpstudy,启动wamp,虽启动成功,但仍然无法使用phpmyadmin登录数据库管理页面. 2.查看到系统服务有mysql服务,检查属性均为emsoa ...