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. Linux命令四

    作业一: 1) 开启Linux系统前添加一块大小为20G的SCSI硬盘 2) 开启系统,右击桌面,打开终端 安装的是命令行界面 3) 为新加的硬盘分区,一个主分区大小为10G,剩余空间给扩展分区,在扩 ...

  2. python考试

    py4测试题 1.8<<2等于?322.通过内置函数计算5除以2的余数 divmod(5,2)3.s=[1,"h",2,"e",[1,2,3],&q ...

  3. YUI笔记 1 模块加载

    我们通常开发js程序就是使用<script>标签把脚本引入到页面中进行开发,如果是简单的逻辑还好,但是如果是比较庞大的大规模js开发,可能会出现下面的问题: 1.  <script& ...

  4. 剑指offer--29.从上往下打印二叉树

    层序遍历,队列 ------------------------------------------------------------------------------------- 时间限制:1 ...

  5. poscms仿站知识点总结(一)

    最近在做基于poscms系统的企业站仿站项目,这个系列用于总结项目中遇到的一些前端问题,至于poscms,待我摸透之后再总结... 进入正题吧,仿站,首先是用仿站小工具把要仿的模板站扒下来,有时候会出 ...

  6. *android判断手机号的运营商

    TextView tv=(TextView)findViewById(R.id.tv); TelephonyManager telManager = (TelephonyManager) getSys ...

  7. c++指针初探

    业余时间准备重温一下c++,因为在阅读Android源码到native层的时候感觉有点吃力,只是在大学时候很不用心的学过c++,所以重温下以便打好一些编程基础知识,本篇就很简单的对c++的指针做初步的 ...

  8. mac brew安装使用卸载

    (一)安装 1.浏览器打开brew.sh,进入homebrew主页.找到install homebrew 的命令: /usr/bin/ruby -e "$(curl -fsSL https: ...

  9. 从云主机上下载文件到本地+获取外网地址(linux & Windows)

    云主机上下载有集中方法,腾讯论坛有一遍文章:向云服务器上传下载文件方法汇总 货比三家,最终还是选择了rsync 下载代码如下 rsync ubuntu@123.207.251.217:/var/www ...

  10. python的一些开源库

    SQLAlchemy——数据持久层框架 简介 SQLAlchemy 主要由两部分组成,一个 SQL 工具包和一个关系对象映射(ORM),它能让开发者完全发挥出 SQL 的灵活性与强大的能量.他实现了一 ...