HDU 1087 Super Jumping! Jumping! Jumping!

Super Jumping! Jumping! Jumping!详解(动态规划) Problem Description 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... 阅读详情

传送门

这道题是 最大递增子序列和 问题。和 最长递增子序列 问题是差不多的。(LIS)

这道题完全不用管那两个起点终点,因为它说了从起点可以直接到任何一个棋子,从任何一个棋子也可以直接到终点,而且起点终点没有数。
然后棋子排成一列,每个棋子上都有一个正整数。路线必须向前但可以不连续(符合子序列的定义),而且跳跃路径上的数必须越来越大(严格递增),在满足以上前提下求出最大的路径和(每个棋子上的数相加)。

还是来回顾一下子序列和子串的区别,给一个大小为n的数组,我认为,子串的数量等于区间的数量,为n(n+1)/2;而子序列的数量等于子集的数量再减一(因为一般来说子序列是不能什么都不选的),为2^n-1。而一般所说的子序列和子集还是有区别,集合不关注顺序,而子序列应该保证还是原数组的顺序(结合题目所说必须向前跳)。
所以LIS这类问题的复杂度不再是O(n)(最大子串和),而是O(n^2)。

思路和最大子串和的问题很相似,都是用一个dp数组表示以当前元素为尾的那个子问题的最优解。不同的是,最大子串和的当前状态只由上一个状态得出,而LIS的当前状态可以由之前的所有状态得出,所以这就多了一层循环。

最后,最大递增子序列和 问题和 最长递增子序列 问题基本一致,区别仅在于dp数组用a[]还是1。


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
using namespace std;         // LIS 最长/最大 递增子序列(非子串)

const int MAXN = 1e3;
int N;
int a[MAXN];
int sum[MAXN];               // 表示一定要由a[i]为尾的最大递增子序列和!!
int ans;

void init()
{
	ans = -1e9;
}

int main()
{
	for (; ~scanf("%d", &N);)
	{
		if (N == 0) break;
		init();
		for (int i = 0; i < N; i++)
			scanf("%d", &a[i]);

		sum[0] = a[0];                               // 如果求最长递增子序列的长度,这里就是1
		for (int i = 1; i < N; i++)
		{
			int t = 0;
			for (int j = 0; j < i; j++)              // 
				if (a[j] < a[i])                     // 没有等号就是要求严格递增
					t = max(t, sum[j]);
			sum[i] = t + a[i];
		}
		for (int i = 0; i < N; i++)
			ans = max(ans, sum[i]);
		printf("%d\n", ans);
	}

	return 0;
}
WorkBuddy最新更新特性(2026-07-21) WorkBuddy最新更新特性 阅读详情

相关推荐

axi ps读写pl_PL读写DDR:Datamover能干什么

最近发现工程项目中一直在用AXI-DMA。这玩意儿搬数据倒是没问题,就是用axi-lite配置起来非常反人类。。。简单的办法其实是用datamover ip核。这个ip核能干嘛呢。准备写个文章解析一下。由于好多feature没用过,所以仅仅看文档可能理解有误,欢迎指出错误。首先扫个盲:MM2S指的是Memory map to stream. 读DDR. S2MM指的是steam to memory...

weixin_35908791的博客 1597

Super Jumping! Jumping! Jumping!题解

这道题就是把最长上升子序列的dp数组用来存最大值就行了。 #include <iostream> #include<string.h> using namespace std; typedef long long ll; ll dp[1010]; ll v[1010]; int main() { int n; while(cin>>n&amp...

qq_41641469的博客 170

Wine7.22实战:如何在Ubuntu上完美运行通达信和微信(附字体配置技巧)

本文详细介绍了如何在Ubuntu系统上使用Wine7.22版本,完美运行通达信和微信这两款Windows专属软件。通过选择稳定的Wine7.22版本、利用现成的兼容容器,并重点解决了中文字体渲染的核心难题,提供了从环境搭建、字体配置到软件安装调优的一站式实战指南,帮助用户在Linux环境下无缝使用关键金融与通讯工具。

weixin_29280657的博客 549

super,jumping!jumping!jumping!做题总结

在每一组的数字串中找出一个递增子序列(该子序列等于或包含于原数字串),使得该递增子序列的元素相加之和最大。用动态规划!!!!!

QXinHan的博客 458

Redis 可视化工具 RedisInsight 的保姆级安装以及使用(最新)

Redis 可视化工具 RedisInsight 的保姆级安装以及使用(最新)

一名全栈小白的博客 1万+

告别环境配置噩梦:VSCode + MinGW 下 OpenGL (glad/glm/glfw) 一站式配置指南(含常见错误排查)

本文提供了一份详细的VSCode与MinGW下OpenGL开发环境配置指南,涵盖glad、glm和glfw三大核心库的安装与调试。通过逐步指导解决常见错误,帮助开发者快速搭建高效的OpenGL开发环境,特别适合初学者避免环境配置中的常见陷阱。

weixin_42557803的博客 490

Super Jumping! Jumping! Jumping! (上升子序列的最大和问题)

问题链接:https://vjudge.net/problem/HDU-1087 翻译: 现在,有一种叫“超级跳高”的象棋游戏。跳!跳!在HDU非常受欢迎。也许你是个好孩子,对这个游戏知之甚少,所以我现在就把它介绍给你。 这个游戏可以由两个人或两个人以上玩。它由一个棋盘棋(盘)、一些棋子(棋子),和所有的棋子都是由一个正整数或“开始”或“结束”。玩家从起点开始,最终必须跳到终点。在跳跃的过程中,玩...

zaiyang遇见 323

NS-3 和Aqua-sim-ng 学习笔记(一)

因为要搞水下网络,OMNET++不太合适,就转Aqua-sim。这是基于NS-2上的模型,NS-2需要额外学一门tcl脚本语言。 正好查到它的一个升级版Aqua-sim-NG,在github上,https://github.com/rmartin5/aqua-sim-ng是基于NS-3的,只需要基本的C++,不用学tcl语言。美滋滋。 装好ubuntu之后,安装NS-3和Aqu...

diboshang8820的博客 2191

Super Jumping! Jumping! Jumping!

Problem Description 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 yo...

知思言乐的博客 229

深度解析快递柜管理系统的C++实现:设计与实现

本文详细介绍了一个基于C++的快递柜管理系统的设计与实现,包括系统需求分析、架构设计、数据库设计、关键功能模块实现和测试与验证。通过详细的代码示例和理论分析,读者可以全面了解如何开发一个完整的快递柜管理系统。希望本文能够为读者在实际项目开发中提供有价值的参考。

m0_57781768的博客 713

用 MATLAB 实现鼻子和嘴的检测

为了方便起见,这里我们使用了 CascadeObjectDetector 中自带的 haarcascade_frontalface_alt2.xml 文件,该文件包含了多个包含鼻子和嘴的样本图像。其中 bbox 变量表示检测到的所有鼻子和嘴的边界框信息。在图像处理中,鼻子和嘴的检测是十分重要的一项任务。本文将介绍如何使用 MATLAB 实现鼻子和嘴的检测,并提供相应的源代码。然后,我们可以调用之前创建的 detector 对象来进行鼻子和嘴的检测。综上所述,我们可以使用以上代码实现鼻子和嘴的检测。

qq_39605374的博客 256

hdu 1087 Super Jumping! Jumping! Jumping!(dp)

hdu 1087 Super Jumping! Jumping! Jumping! http://acm.hdu.edu.cn/showproblem.php?pid=1087 ProblemDescription Nowadays,akindofchessgamecalled“SuperJumping!Jumping!Jumping!”isv...

diansitao5461的博客 94

【华为OD技术面试真题 - 技术面】- C++面试题(1)

2024华为OD面试手撕代码真题目录以及八股文真题目录

算法大师! 3398

HDU 【1087】Super Jumping! Jumping! Jumping

Problem Description 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 yo

进击的小白 207

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

HDU - 1087 Super Jumping! Jumping! Jumping!

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

zamaochick的博客 395

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

HDU-1087 Super Jumping! Jumping! Jumping!

动态规划 HDU-1087 Super Jumping! Jumping! Jumping! 题目链接: 杭电1087 题目大意: 给定一列数字 求最大顺序子列和 子列中的数字必须严格由小到大 解题思路: 将数组储存 dp[i]储存以arr[i]为结尾的最大值 循环当前判断的前面的数字 如果当前的数字比之前的数字大 则进行dp的替换 方程为:dp[i] = max(dp[i], dp[j]...

鱼头的水题之路 301

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

HDU 1087 - Super Jumping! Jumping! Jumping!

题目链接:HDU - 1087 Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) ...

Ripcord丶的博客 188

hdu1087 Super Jumping! Jumping! Jumping!

Problem Description 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 yo

South_stream 2031

HDU 1087 super jumping!jumping!jumping!

problem description 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 yo...

沧浪之水 491

HDU 1087 Super Jumping! Jumping! Jumping!

B - Super Jumping! Jumping! Jumping! Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 10

Inite的博客 601

HDU - 1087 Super Jumping! Jumping! Jumping!

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

GJLfly的博客 280

hdu 1087 Super Jumping! Jumping! Jumping! 【动规】

题目 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 consis

QYQHxyh的博客 258

杭电 1087 hdu (Dynamic Programming)Super Jumping! Jumping! Jumping!

杭电 1087 hdu (Dynamic Programming) Super Jumping! Jumping! Jumping! *Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 66856 Accepted Submission(s): 31301* Problem Description Nowadays, a kind of chess g

邓汪涛的博客 255

HDu1087 Super Jumping! Jumping! Jumping!

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 分析:简单dp;dp[i] = max (dp[i], dp[j] + a[i]) 1 #include<iostream> 2 #include<sstream> 3 #include<cstdio> 4 #include&l...

weixin_30449453的博客 82

hdu 1087 Super Jumping! Jumping! Jumping!

Problem Description 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 yo

要去相信,没有到不了的明天 588
上一篇: HDU 1081 To The Max
下一篇: HDU 2571 命运
Crossing over
博客等级 码龄10年 6粉丝 113原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值