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

最长子序列的同款题目,这次求的不是最长子序列的长度,而是最长子序列的和,只需要把最长子序列模板的值做一下修改,一般情况下dp数组的值是在自己之前的最长子序列的长度,这里换为在自己之前的最长子序列的和即可。

AC代码

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int dp[1005];
int num[1005];
int main()
{int n;while(cin>>n&&n){int maxl=-1;memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)cin>>num[i];for(int i=1;i<=n;i++){for(int j=1;j<i;j++)if(num[i]>num[j])dp[i]=max(dp[i],dp[j]+num[i]);if(dp[i]==0) dp[i]=num[i];if(maxl<dp[i]) maxl=dp[i];}cout<<maxl<<endl;}return 0;
}

Super Jumping! Jumping! Jumping! 最长上升子序列+DP相关推荐

  1. HDU1087 Super Jumping! Jumping! Jumping!【最长上升子序列+DP】

    问题链接:HDU1087 Super Jumping! Jumping! Jumping!. 问题简述:参见上述问题描述. 问题分析: 这是一个最长上升子序列问题,使用DP算法实现. 定义dp[i]= ...

  2. Bailian2806 公共子序列【最长公共子序列+DP】

    2806:公共子序列 描述 我们称序列Z = < z1, z2, -, zk >是序列X = < x1, x2, -, xm >的子序列当且仅当存在 严格上升 的序列< ...

  3. NUC1776 Tiling Up Blocks【二维最长上升子序列+DP】

    Tiling Up Blocks 时间限制: 1000ms 内存限制: 10000KB 通过次数: 2总提交次数: 2 问题描述 Michael The Kid receives an interes ...

  4. Vijos P1571 笨笨的导弹攻击【最长上升子序列+DP】

    背景 在那遥远的地方,有个小目标-- 笨笨:导弹准备! 路人甲:(这么小个目标都要欺负--)老大,导弹只有一部分可以用-- 笨笨:不管那么多,有多少就打多少! 描述 为了彻底打击目标,笨笨要使用足够多 ...

  5. Vijos P1303 导弹拦截【最长上升子序列+DP】

    背景 实中编程者联盟为了培养技术精湛的后备人才,必须从基础题开始训练. 描述 某国为了防御敌国的导弹袭击,研发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度, ...

  6. HDU1257 最少拦截系统【最长上升子序列+DP】

    问题链接:HDU1257 最少拦截系统. 问题简述:参见上述问题描述. 问题分析:这个问题的本质是求最长上升子序列.与<POJ2533 Longest Ordered Subsequence[最 ...

  7. NYOJ 36 最长公共子序列 dp

    最长公共子序列 点击打开链接时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列. tip:最长公共子序 ...

  8. LeetCode 1035. 不相交的线(最长公共子序列DP)

    文章目录 1. 题目 2. 解题 1. 题目 我们在两条独立的水平线上按给定的顺序写下 A 和 B 中的整数. 现在,我们可以绘制一些连接两个数字 A[i] 和 B[j] 的直线,只要 A[i] == ...

  9. 51nod1134最长递增子序列(dp)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1134 这里说下,最长上升子序列和最长不降子序列几乎一样,只是判 ...

  10. Bailian2945 导弹拦截【最长上升子序列+DP】

    2945:拦截导弹 总时间限制: 1000ms 内存限制: 65536kB 描述 某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高 ...

最新文章

  1. 【LeetCode】136. Single Number 解题小结
  2. 兼容IE低版本的文件上传解决方案
  3. MQTT在Windows下搭建MQTT服务器
  4. virtualbox中文技术文档_随笔--西门子STEP7中如何寻找技术文档
  5. linux g命令,【Linux】常用命令大全
  6. 用epl的開源產品開發,可以閉源
  7. 计算机一级考试word操作题主要题型,(word)计算机一级考试题型.doc
  8. 第九章 图形用户界面的并行化(待续)
  9. aop判断方法是否执行成功_判断图中是否有环的三种方法
  10. android连接此设备时打开,QtScrcpy: Android实时投屏软件,此应用程序提供USB(或通过TCP/IP)连接的Android设备的显示和控制。它不需要任何root访问权限...
  11. 618 技术特辑(一)不知不觉超预算3倍,你为何买买买停不下来?
  12. pythonlist循环添加元素_list.append()在for循环中每次添加的都是最后的一个元素汗血宝马...
  13. Selenimu做爬虫 - oscarxie - 博客园
  14. R语言作图之ggplot2初识(1)
  15. js获取url传递参数
  16. Net设计模式实例系列文章总结
  17. linux分区命令mtd,修改IPQ4019/4018的MTD分区
  18. DOS命令大全:MS-DOS命令详解
  19. 计算机硬件关系密切,与计算机硬件关系最密切的软件是( ).
  20. 基于node.js的网页聊天系统设计与实现

热门文章

  1. oracle备份恢复学习
  2. [名人观点--刘振飞] bug管理
  3. 使用单元测试工具TestDriven.NET调试程序
  4. httpClient测试
  5. 统计学习方法9—EM算法
  6. Linux基本命令总结(六)
  7. 【实验报告】二 网络嗅探与欺骗
  8. Oracle体系结构三(学习笔记)
  9. cocos2dx android运行Luac编译后的lua代码
  10. 用命令行发邮件——让你更加了解smtp