HDU1087

Problem Descrption

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

问题连接:http://acm.hdu.edu.cn/showproblem.php?pid=1087

问题分析:

玩家从起点开始,最后必须跳到终点.在跳跃过程中,玩家将访问路径中的棋子,但每个人都必须从一个棋子跳到另一个绝对更大(你可以假设起点是一个最小值和终点是最大值)。)。所有的球员都不能后退。一个跳跃可以从棋子跳到下一步,也可以穿过许多棋子,甚至你可以直线从起点到终点。当然你在这种情况下是零。一个球员是胜利者当且仅当他能根据他的跳跃方案获得更大的分数。请注意,您的得分来自您跳转路径中的棋子上的值之和。您的任务是根据给定的棋子列表输出最大值。

#include<iostream>
#include<cstring>int main(){int n;int a[1000010],b[1000010],i,j,s;while(scanf("%d",&n)&&n!=0){memset(b,0,sizeof(b));//b数组为递增序列到此的最大和for(i=1; i<=n; i++)scanf("%d",&a[i]);int k=-30000;//结果初始化为最小值,也有可能是负数for(i=1; i<=n; i++){s=-30000;//初始化为最小值for(j=0; j<i; j++)if(a[j]<a[i]&&s<b[j])s=b[j];//找到a[i]之前的最大递增和b[i]=s+a[i];//从开始到现在的最大递增序列和if(b[i]>k)k=b[i];}printf("%d\n",k);}return 0;}

其实就是求最长递增子序列和

AC代码:

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/330361.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

转-BFF调研-1

转自&#xff1a; https://blog.csdn.net/duola8789/article/details/89332064 前端开发中存在的难问题 多端应用&#xff0c;不同类型客户端对数据、API有个性化的需求服务聚合&#xff0c;单一后端为多个前端团队提供接口&#xff0c;导致跨团队协作低效&#xff0c;资源协…

JDK8新特性之Stream流

转载自 JDK8新特性之Stream流 是什么是Stream流 java.util.stream.Stream Stream流和传统的IO流&#xff0c;它们都叫流&#xff0c;却是两个完全不一样的概念和东西。 流可以简单的说是处理数据集合的东西&#xff0c;可以申明式流式API来处理集合&#xff0c;而不是写一个…

(转)贫血和富血

转自&#xff1a; https://blog.csdn.net/t0404/article/details/51865174 贫血vs富血 我们来回顾一下。在企业架构模式中&#xff0c;业务层的实现一般有两种模式&#xff1a;一种是事务角本模式&#xff08;Transaction script&#xff09;&#xff0c;另一种是领域模型模式…

JDK8的排序大法!!

转载自 屌炸天&#xff0c;JDK8的排序大法&#xff01;&#xff01; 今天总结了下JDK中排序的方法&#xff0c;包括JDK8中强大的lambda表达式及函数式接口运用&#xff0c;不废话&#xff0c;请看下面示例。 public class Test {public static void main(String[] args) {Lis…

康复题11

定义一个二维数组&#xff1a; int maze[5][5] {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,}; 它表示一个迷宫&#xff0c;其中的1表示墙壁&#xff0c;0表示可以走的路&#xff0c;只能横着走或竖着走&#xff0c;不能斜着走&#xff0c;要求…

JDK8新特性之函数式接口

转载自 JDK8新特性之函数式接口 什么是函数式接口 先来看看传统的创建线程是怎么写的 Thread t1 new Thread(new Runnable() {Overridepublic void run() {System.out.println("t1");} }); t1.start(); 再来看看使用了函数式接口是怎么写的 Thread t2 new Thre…

hashCode和identityHashCode的区别你知道吗?

转载自 hashCode和identityHashCode的区别你知道吗&#xff1f;hashCode 关于hashCode参考之前的文章&#xff0c;点击参考之前文章。 identityHashCode identityHashCode是System里面提供的本地方法&#xff0c;java.lang.System#identityHashCode。 /*** Returns the same ha…

转:drop、truncate和delete的区别与选择

转自&#xff1a; https://blog.csdn.net/shadow_zed/article/details/78252494 &#xff08;1&#xff09;日志与事务 1.delete语句执行删除的过程是每次从表中删除一行&#xff0c;并且同时将该行的删除操作作为事务记录在日志中保存以便进行进行回滚操作。 2.truncate tab…

Java高级篇——深入浅出Java类加载机制

转载自 Java高级篇——深入浅出Java类加载机制类加载器简单讲&#xff0c;类加载器ClassLoader的功能就是负责将class文件加载到jvm内存。类加载器分类从虚拟机层面讲分为两大类型的类加载器&#xff0c;一是Bootstrap Classloader即启动类加载器&#xff08;C实现&#xff09;…

康复题21

For a positive integer n lets define a function f: f(n)   - 1  2 - 3  ..  ( - 1)nn Your task is to calculate f(n) for a given integer n. Input The single line contains the positive integer n (1 ≤ n ≤ 1015). Output Print f(n) in a …

转: databasemetadata 无法获取数据库表备注的解决方法

转自&#xff1a; https://blog.csdn.net/10km/article/details/77389038 mysql/jdbc:设置useInformationSchematrue读取表注释信息(table_comment) 问题描述 今天在读取表的注释信息(COMMENT)时,发现返回的REMARKS字段返回居然是null. 以下是代码示例: DatabaseMetaData me…

IntegerCache的妙用和陷阱

转载自 IntegerCache的妙用和陷阱 考虑下面的小程序&#xff0c;你认为会输出为什么结果&#xff1f; public class Test {public static void main(String[] args) {Integer n1 123;Integer n2 123;Integer n3 128;Integer n4 128;System.out.println(n1 n2);System.ou…

转:线性代数知识汇总

https://blog.csdn.net/MyArrow/article/details/53365048 1. 线性代数知识图谱 线性代数是代数学的一个分支&#xff0c;主要处理线性关系问题。线性关系意即数学对象之间的关系是以一次形式来表达的。例如&#xff0c;在解析几何里&#xff0c;平面上直线的方程是二元一次…

康复题25

都说天上不会掉馅饼&#xff0c;但有一天gameboy正走在回家的小径上&#xff0c;忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了&#xff0c;这馅饼别处都不掉&#xff0c;就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了&#xff0c;所以gameboy马…

2020-09-17

https://www.zhihu.com/question/32729130

高级JAVA码农必须搞清楚它们的区别:instanceof、isInstance、isAssignableFrom

转载自 高级JAVA码农必须搞清楚它们的区别&#xff1a;instanceof、isInstance、isAssignableFrominstanceof、isInstance、isAssignableFrom这几个有没有接触过&#xff0c;或者接触过部分&#xff1f;定义a instanceof B a是B的实例&#xff0c;B是类或者接口、父类或父接口&…

康复题12

An elephant decided to visit his friend. It turned out that the elephants house is located at point 0 and his friends house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Deter…

Java架构师必看的10本书

转载自 Java架构师必看的10本书1、大型网站系统与JAVA中间件实践 本书围绕大型网站和支撑大型网站架构的Java中间件的实践展开介绍。 从分布式系统的知识切入&#xff0c;让读者对分布式系统有基本的了解&#xff1b;然后介绍大型网站随着数据量、访问量增长而发生的架构变迁&a…

转: Spark 的核心概念 RDD

转自&#xff1a; https://juejin.im/post/6844903826953076750 1.RDD 概述 1.1 什么是 RDD ? RDD(Resilient Distributed Dataset) 叫着 弹性分布式数据集 &#xff0c;是Spark 中最基本的抽象&#xff0c;它代表一个不可变、可分区、里面元素可以并行计算的集合。 RDD …

SpringMVC @Transactional的陷井大坑引发No Session found for current thread

一、TransactionManager事务配置 &#xff08;1&#xff09;注解配置 配置spring的xml加Transactional<tx:annotation-driven transaction-manager"transactionManager" proxy-target-class"true" /> &#xff08;2&#xff09;xml配置 <tx:adv…