HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)
发布日期:2021-06-29 13:35:55 浏览次数:2 分类:技术文章

本文共 2356 字,大约阅读时间需要 7 分钟。

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 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[i]

最后找出最大的dp[i]就是答案~~

import java.util.Scanner;/** * @author 陈浩翔 * * 2016-5-26 */public class Main{
public static void main(String[] args) { Scanner sc =new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); if(n==0){ break; } int a[]=new int[n]; int dp[]=new int[n]; for(int i=0;i
max){ max=dp[j]; } } dp[i]=a[i]+max; } int max=dp[0]; for(int i=1;i
max){ max=dp[i]; } } System.out.println(max); } }}

转载地址:https://chenhx.blog.csdn.net/article/details/51503423 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:CSS---网络编程
下一篇:HDOJ/HDU 1073 Online Judge(字符串处理~)

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月16日 04时32分27秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

【经验分享】RT-Thread UART设备驱动框架初体验(中断方式接收带\r\n的数据) 2019-04-29
单片机里面的CPU使用率是什么鬼? 2019-04-29
推荐一个优质Linux技术公众号-作者都是一线Linux代码贡献者们哦 2019-04-29
RT-Thread 编程风格指南 2019-04-29
95后高校电子教师,软硬兼修有趣有料! 2019-04-29
使用 STM32 通用 Bootloader ,让 OTA 更加 Easy 2019-04-29
Cache 的基本概念与工作原理 2019-04-29
装机量超亿台 RISC-V +IoT OS!中科蓝讯与RT-Thread战略合作,共推自主物联网生态发展 2019-04-29
Android程序员必备!面试一路绿灯Offer拿到手软,Android面试题及解析 2019-04-29
Android程序员的春天!12个View绘制流程高频面试题,分享PDF高清版 2019-04-29
深入交流安卓!新鲜出炉的Android面试真题集锦我给你们整理出来了!Android面试题及解析 2019-04-29
深入浅出Android开发!你会的还只有初级工程师的技术吗?一线互联网公司面经总结 2019-04-29
深度剖析原理!超全Android中高级面试复习大纲,含BATJM大厂 2019-04-29
温故而知新!Android开发者该学习哪些东西提高竞争力?成功入职阿里 2019-04-29
火爆知乎的Android面试题-Android-App的设计架构经验谈,大厂内部资料 2019-04-29
看完直接怼产品经理!Android多进程从头讲到尾,跳槽薪资翻倍 2019-04-29
快速从入门到精通!面试的时候突然遇到答不上的问题怎么办?已拿到offer 2019-04-29
Android开发知识体系!腾讯+字节+阿里面经真题汇总,成功入职阿里 2019-04-29
android开发语言!大厂经典高频面试题体系化集合,移动架构师成长路线 2019-04-29
typescript学习(进阶) 2019-04-29