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. spring定时器的定义

    1.0/5 * * * * ?表示多长时间: 每 5 秒执行一次 七个域从左到右依次是,秒,分,时,日,月,周几,年....最后一个可选.同样是七个域与当前时间匹配的时候则执行... n/m 表示从n ...

  2. Android应用实现Push推送消息原理

            本文介绍在Android中实现推送方式的基础知识及相关解决方案.推送功能在手机开发中应用的场景是越来起来了,不说别的,就我 们手机上的新闻客户端就时不j时的推送过来新的消息,很方便的阅 ...

  3. 目标跟踪之相关滤波:CF及后续改进篇

    一. 何为相关滤波? Correlation Filter 最早应用于信号处理,用来描述两个信号之间的相关性,或者说相似性(有点像早期的概率密度),先来看定义: 对于两个数据 f 和 g,则两个信号的 ...

  4. Java 实现--时间片轮转 RR 进程调度算法

    时间片轮转(Round-Robin)调度算法是操作系统一种比较公平的进程调度的方式,这种方式使得就绪队列上的所有进程在每次轮转时都可以运行相同的一个时间片. 基本原理 算法实现原理是,按进程到达顺序( ...

  5. java网络编程TCP传输—流操作—服务端反馈与客户端接收

    在读取完流后,服务端会向客户端返回一些数据,告诉客户端,已经写完了. 在这里和”流操作—拿到源后的写入动作“差不多,客户端同样以byte与Buffered两种缓冲读取作为例子,同时,.也是希望大家给补 ...

  6. C/C++ 笔试题一

    摘自 网络上的 笔试题,据说是华为的,考察的内容还算全面,也很细致: 答案 疏略 检查了下,应该没有什么大问题,但是 还是那句话,尽信之不如无,所以还是要自己思考 1.static有什么用途?(请至少 ...

  7. 前端之JavaScript 01

    一JavaScript介绍 js历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEase.(客户端执行的语言 ...

  8. RabbitMQ学习系列一安装RabbitMQ服务

    RabbitMQ学习系列一:windows下安装RabbitMQ服务 http://www.80iter.com/blog/1437026462550244 Rabbit MQ 是建立在强大的Erla ...

  9. oracle fn project 开源faas 框架

    1. 介绍 Fn is an event-driven, open source, functions-as-a-service compute platform that you can run a ...

  10. linux下修改ip地址

    1.more  /etc/sysconfig/network-scripts/ifcfg-eth0 2.ifconfig eth0 192.168.1.211 netmask 255.255.255. ...