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 求一串递增的数字总和的最大值 借这里放下最长上升子序列的模板(求最大长度和最大总和的)
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<cmath>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const int inf = 1e9;
int a[], dp[], num[], n;
int calc( int sign ) { //求最长,nlog(n)
fill( dp, dp+, inf );
int ans = ;
for( int i = ; i < n; i ++ ) {
int index = lower_bound( dp, dp+ans, a[i]*sign ) - dp; //lower为求严格递增,upper为求非严格递增
dp[index] = a[i]*sign;
ans = max( ans, index + );
}
return ans;
}
int lins() {
return calc();
}
int lnds() {
return calc(-);
}
int calc_max() { //求最大,n^2
int ans = ;
for( int i = ; i < n; i ++ ) {
dp[i] = a[i];
for( int j = ; j < i; j ++ ) {
if( a[j] < a[i] ) {
dp[i] = max( dp[i], dp[j]+a[i] );
}
}
ans = max( ans, dp[i] );
}
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
while( cin >> n ) {
memset( num, , sizeof(num) );
if( !n ) {
break;
}
for( int i = ; i < n; i ++ ) {
cin >> a[i];
}
cout << calc_max() << endl;
}
return ;
}

最长上升子序列模板 hdu 1087 Super Jumping! Jumping! Jumping!的更多相关文章

  1. 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!

    来源:点击打开链接 最长上升子序列的考察,是一个简单的DP问题.我们每一次求出从第一个数到当前这个数的最长上升子序列,直至遍历到最后一个数字为止,然后再取dp数组里最大的那个即为整个序列的最长上升子序 ...

  2. HDU 1087 Super Jumping! Jumping! Jumping

    HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...

  3. HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  4. HDU - 1087 Super Jumping!Jumping!Jumping!(dp求最长上升子序列的和)

    传送门:HDU_1087 题意:现在要玩一个跳棋类游戏,有棋盘和棋子.从棋子st开始,跳到棋子en结束.跳动棋子的规则是下一个落脚的棋子的号码必须要大于当前棋子的号码.st的号是所有棋子中最小的,en ...

  5. hdu 1087 Super Jumping!(类最长上升子序列)

    题意:在一组数中选取一个上升子序列,使得这个子序列的和最大. 解:和最长上升子序列dp过程相似,设dp[i]为以第i位为结尾最大和,那么dp[i]等于max(dp[0],dp[1],,,,,dp[i- ...

  6. HDU 1087 Super Jumping! Jumping! Jumping! (动态规划、最大上升子序列和)

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

  7. HDU 1087 Super Jumping! Jumping! Jumping! --- DP入门之最大递增子序列

    DP基础题 DP[i]表示以a[i]结尾所能得到的最大值 但是a[n-1]不一定是整个序列能得到的最大值 #include <bits/stdc++.h> using namespace ...

  8. HDU 1087 Super Jumping! Jumping! Jumping! --- DP入门之最大上升子序列

    题目链接 DP基础题 求的是上升子序列的最大和 而不是最长上升子序列LIS DP[i]表示以a[i]结尾所能得到的最大值 但是a[n-1]不一定是整个序列能得到的最大值 #include <bi ...

  9. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

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

随机推荐

  1. 100天搞定机器学习|Day13-14 SVM的实现

    昨天我们学习了支持向量机基本概念,重申数学推导原理的重要性并向大家介绍了一篇非常不错的文章.今天,我们使用Scikit-Learn中的SVC分类器实现SVM.我们将在day16使用kernel-tri ...

  2. 9-2、大型项目的接口自动化实践记录----递归判断两个json串是否相等

    1.已知json串构成的情况下判断 先构造一下场景,假设已经把各个数据都移除掉不对比的字段 图1 预期.实际结果,复杂接口返回多层嵌套json时,同下 图2 预期.实际结果值为:{child_json ...

  3. 二叉查找树(查找、插入、删除)——C语言

    二叉查找树 二叉查找树(BST:Binary Search Tree)是一种特殊的二叉树,它改善了二叉树节点查找的效率.二叉查找树有以下性质: (1)若左子树不空,则左子树上所有节点的值均小于它的根节 ...

  4. mysql docker 主从配置

    主从复制相关 前置条件: docker安装的mysql是5.7.26版本 1. 编排docker-compose文件如下: version: '3' services: mysql-master: v ...

  5. 变量Variable

    变量Variable 内存 #conding:utf-8 a = 1 #conding:utf-8 a = 1 b = a #conding:utf-8 a = 1 b = a a = 2 命名规则 ...

  6. Mac 安装 homebrew 流程 以及 停在 Updating Homebrew等 常见错误解决方法

    懒人操作顺序:S_01>>>S_02>>>S_03 首先这是homebrew的官网 https://brew.sh/index_zh-cn 安装方法是在终端中输入 ...

  7. 论文解读2——Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition

    背景 用ConvNet方法解决图像分类.检测问题成为热潮,但这些方法都需要先把图片resize到固定的w*h,再丢进网络里,图片经过resize可能会丢失一些信息.论文作者发明了SPP pooling ...

  8. [Spring cloud 一步步实现广告系统] 20. 系统运行测试

    系统运行 经过长时间的编码实现,我们的主体模块已经大致完成,因为之前我们都是零散的对各个微服务自行测试,接下来,我们需要将所有的服务模块进行联调测试,Let's do it. 清除测试数据&测 ...

  9. 03 requests模块基础

    1. requests 模块简介 什么是requests 模块 requests模块是python中原生的基于网络请求的模块,功能强大,用法简洁高效.在爬虫领域中占据着半壁江山的地位.requests ...

  10. 谈谈JVM垃圾回收

    概述 Java运行时区域中,程序计数器,虚拟机栈,本地方法栈三个区域随着线程的而生,随线程而死,这几个区域的内存分配和回收都具备确定性,不需要过多考虑回收问题.而Java堆和方法区则不一样,一个接口的 ...