HDU1087 - Super Jumping! Jumping! Jumping! (Java)

HDU 动态规划(46道题目 立即下载

 题目描述

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.

给定一条长度为n的序列,其中一定存在一条元素和最大的严格上升子序列,求这条序列的元素和。

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.

包含多组输入数据,每组数据占一行,每行一个整数n,接着n个数a_1, a_2, ..., a_n (a_i在32位有符号整型范围内),n = 0表示输入结束 (0 <= n <= 1000)。

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

Output

4
10
3

代码:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            int n = in.nextInt();
            if(n == 0)
                break;
            int[] a = new int[n+1];
            for (int i = 1; i <= n; i++) {
                a[i] = in.nextInt();
            }
            int[] dp = new int[n+1];
            int max = -1;
            for (int i = 1; i <= n; i++) {//前i项的最大和为dp[i]
                int sum = -1;
                for (int j = 0; j < i; j++) {//在[0,i)中找一个最大的和
                    if(a[j] < a[i]){
                        sum = Math.max(sum,dp[j]);
                    }
                }
                dp[i] = sum + a[i];//以前的最大和加上这个数得到的和
                max = Math.max(max,dp[i]);
            }
            System.out.println(max);
        }
    }

}

题目链接

1321 -- 棋盘问题

Visual Studio报错TRK0005找不到CL.exe?三步彻底解决环境变量问题 本文详细解析了Visual Studio报错TRK0005找不到CL.exe的根本原因,并提供了三步彻底解决环境变量问题的方案。从验证安装完整性到配置永久环境变量,再到注册表级修复,帮助开发者建立健壮的开发环境配置体系,确保编译链稳定运行。 阅读详情

相关推荐

vivado运行时报错 license文件更新操作

vivado使用:SYNTHESIS->Run Synthesis 时报错 [Common 17-345] A valid license was not found for feature ‘Synthesis’ and/or device ‘xc7vx485t’. Please run the Vivado License Manager for assistance in determiningwhich features and devices are licensed for your sy

qq_44692266的博客 2万+

HDU1087(初识数位dp)

题目链接HDU1087 这道题难在他的思想上,作为入门数位dp的一道基础题并没什么难度,我借此机会写下自己对这题的理解。 动态规划最重要的是掌握他的思想,动态规划的核心思想是把原问题分解成子问题进行求解,也就是分治的思想。 解题思路: 创建数组 a 和数组dp,下标从 1 开始,dp[ i ]表示的是以下标为 i 的元素作为一小段数组的结尾的这段数组的最大值。 比如:dp[ 5 ] = { 1 , 3 , 4 , 2 , 5 } ,dp[ 2 ] 代表以 3 结尾的{1 , 3 }这样一段数组的最大值,因此

HXZ_CREATE的博客 422

嵌入式软件面试常见问题及答案

干了多年的嵌入式,被面试过,也面过不少新人,下面这些是面试中很常见的一些问题及答案,答案可以根据自己的经验自己思考下。--持续补充并更新

weixin_37553721的博客 6039

HDU-1087(最长上升子序列和)

题意:给你一序列,找出一个和最大的上升子序列, 输出它的和。 思路:动态规划,建立dp数组。因为这题要求是上升子序列,我们需要知道当前子序列末尾的值,所以可使dp[i]表示以i结尾的序列的最大和。这样循环到a[i]时,可通过找到dp数组前i-1项的最大值dp[j],并比较a[j](当前序列最后一项)与当前a[i]的大小。如果a[i] &gt; a[j],则a[i]可加到当前序列。若没找到,则以a...

ImwImW的博客 974

ECB oracle——attack

基于ECB oracle的攻击方案前言什么是ECB方案步骤1.确定块大小和明文大小2.暴力破解求明文脚本代码 前言 参考文章:Breaking ECB by prepending your own message. 环境地址:ECB oracle 什么是ECB 分组密码中AES的一种模式(其他还有:CBC、ECB、CTR、OCF、CFB)如图每一块加密是分开的。 方案步骤 1.确定块大小和明文大小 先用一个字符"a"去encrypt返回32个字节的数据(64位16进制)依次用"aa",“aaa”…去en

weixin_44617902的博客 1314

ROS2_Moveit2_Ur5e_Grasp项目详解(二):核心模块功能解析

本文深入解析了ROS2_Moveit2_Ur5e_Grasp项目的核心模块功能。重点阐述了OctoMap建图模块如何为机械臂提供实时三维环境感知,并详细介绍了Robotiq夹爪与MoveIt2的集成控制、UR5e的运动规划策略,以及视觉模块如何协同工作,最终实现从目标检测到动态抓取的完整闭环。

weixin_29254029的博客 116

hdu1087(dp:解决寻找最大序列值问题。dp[n] = max{dp[n],dp[k] + a[n]}【当a[n]>a[k]时执行】)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意: 就是给你一个数字序列,让你寻找一个从小到大排序的子序列是所有这样排序的子序列最大值。比如:下图所示中的,前面的第一个数代表着后面有几个数字。故第一例的数字序列就只是:1 3 2.所以其最大的子序列的值为4,这个子序列为:1 3; 故第二例:1 2 3 4,其最大子序列的值为10,子...

zhoupingqi2017的博客 346

OnlyOffice Docker部署踩坑实录:解决Nginx反向代理导致的editor.bin下载失败

本文详细解析了在Docker中部署OnlyOffice时,因Nginx反向代理配置不当导致editor.bin下载失败的常见问题。通过分析问题根源,提供了从Nginx代理配置、Docker网络设置到OnlyOffice容器内部调整的完整解决方案,并分享了实战调试技巧与性能优化建议,帮助用户彻底解决这一部署难题。

wine的专栏 533

HDU 1087 Super Jumping! Jumping! Jumping!(LIS)

题意: 给你一个需要找你输出一个单调递增子序列的和的最大值。 注意到这样一句话. but everyone must jumps from one chessman to another absolutely bigger. 看到这句话直接想到lis了,然后果断写了一个lis交上去wa了。 然后稍微分析一下,题目要求的是递增的子序列没错,但不是要它的长度,而是要他的值。比如这样一个例子:40 ...

weixin_43736492的博客 174

Android 系统状态栏中实现高斯模糊背景

至此,我们已经完成了在 Android 系统的 SystemUI 中实现高斯模糊背景的过程。通过以上的布局和代码修改,我们可以在状态栏中看到具有高斯模糊效果的背景。同时,为了在不同版本的 Android 系统上适配高斯模糊效果,可能需要进行一些额外的代码调整和兼容性处理。希望本文能够帮助你理解如何在 Android 系统的 SystemUI 中实现高斯模糊背景,并通过提供的源代码进行相应的开发和调试。首先,我们需要在 SystemUI 的布局文件中添加一个用于展示高斯模糊背景的视图。属性来开启模糊效果。

CyberSparkZ的博客 882

Odoo17商城微信支付模块,快速一个实现可在线支付的商城

通过集成微信支付APIv3,Odoo 系统实现了高效、安全的支付流程。Native扫码支付和Jsapi微信浏览器内直接拉起支付为用户提供了更加便捷的支付方式。同时,通过发送下单及支付消息给管理员,商家可以实时了解订单状态并进行相应处理。通过集成微信支付 结合 Odoo 系统内置的商城模块,可以为商家快速实现功能完善、高效的电商解决方案。

AaronZZH 的博客 2270

hdu——1087——Super Jumping! Jumping! Jumping!

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1087 求出最长上升子序列的和 #include #include #include using namespace std; int a[1010],dp[1010]; int main() { int i,j,n,m,k; while(scanf("%d",&

Kamy Shi 856

我的python学习之路

Python 是一门功能强大且易于学习的编程语言,广泛应用于数据分析、人工智能、Web 开发、自动化等领域。以下是一个 Python 学习路径的总结,帮助你系统地掌握 Python 编程。

数据知道的博客 3万+

【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 thi

楚江枫 502

WINCC7.3破解文件

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

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

寒假训练01E:hdu1087

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

某某某的博客 336

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

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丶的博客 189

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

杭电 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

邓汪涛的博客 256

hdu-1087 Super Jumping! Jumping! Jumping!(DP解法)

hdu-1087 Super Jumping! Jumping! Jumping!(DP解法)题目描述 Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35239

oYinGui1 838

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 consists of

Lionel 2069

HDU1087:Super Jumping! Jumping! Jumping!(上升子序列最大和)

HDU1087:Super Jumping! Jumping! Jumping! kuangbin专题十二:E题 Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 41625Accepted Submission(s):...

aboc43983的博客 154

HDU 1087 Super Jumping! Jumping! Jumping!【dp】

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35625    Accepted Submission(s): 16206 Problem Descri

Puya的博客 308

HDU Problem 1087Super Jumping! Jumping! Jumping!

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 31007    Accepted Submission(s): 13894 Problem Descri

博客已搬迁到http://www.cnblogs.com/cniwoq/ 374

hdu1087 Super Jumping! Jumping! Jumping!

题目的大意是从起点开始跳,只能从小到大跳不能从大到小跳,也可以直接从起点跳到终点,并假设起点最小,终点最大,可以一次跳一步也可以一次跳任意多步,问途径的数组的最大和是多少,这个和最长上升子序列其实没什么本质区别,只不过最长上升子序列是求一个长度,也就是说cou = 0然后cou++这种模式,然而此题是把计数器变成sum求和而已 #include #include #include

EventQueue的博客 465

hdoj1087Super Jumping! Jumping! Jumping!【dp】

Super Jumping! Jumping! Jumping! Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 7   Accepted Submission(s) : 2 Problem Description N

走一步再走一步 731

【HDU】1087 - Super Jumping! Jumping! Jumping!(dp)

点击打开题目 Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33314    Accepted Submission(s): 15063

wyg1997 392

hdu1087 Super Jumping! Jumping! Jumping! 超级跳跳跳 最大升序子段和

Super Jumping! Jumping! Jumping!Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 45797    Accepted Submission(s): 21225Problem DescriptionNowaday...

popcjz的博客 1436
上一篇: HDU1257 - 最少拦截系统 (Java)
下一篇: HDU1176 - 免费馅饼 (Java)
Mosyi_
博客等级 码龄5年 1粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值