Question:

Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56626    Accepted Submission(s): 26273

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
 
Author
lcy
 
idea:
first create two arrays to saving the input data,one is data that use to saving the input data and it won't change anyway,the other one is result that storing the input data and will change every circle,it will store the sum of a increasing sub-sequence before this kont in the last, which every element is smaller than it.
it's a simply DP
 
translate in chinese:
定义两个数组,第一个数组是data,用来存储输入的信息,他不会改变,只允许被访问
另外一个数组是result,用来存储第一个节点到每一个节点的递增子序列的和,最后这个数组里存储的都是第一个节点到指定节点的递增子序列的和
然后通过遍历result数组就可以得到最大递增子序列

source code:

import java.util.Scanner;

/**
* 3 1 3 2
* 4 1 2 3 4
* 4 3 3 2 1
* 0
*/
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while(true){
int ammount = sc.nextInt();
if(ammount==0)break;
int[] data = new int[ammount];
int[] result = new int[ammount]; for(int i = 0;i < ammount;i++){
data[i] = sc.nextInt();
result[i] = data[i];
} /**
* 思想:从data数组的第一项到每一项查看,从第一项开始,如果此项比指定项小,就加上,然后进行下一项
*/
for(int i = 1;i < data.length;i++){
for(int j = 0;j < i;j++){
if(data[j] < data[i])result[i] = Math.max(result[i],result[j]+data[i]);
}
}
int ans = -99;
for(int temp:result){
if(temp > ans)ans = temp;
}
System.out.println(ans);
}
}
}

hope that I can help you

that's all

 
 

算法_hdoj_1005的更多相关文章

  1. B树——算法导论(25)

    B树 1. 简介 在之前我们学习了红黑树,今天再学习一种树--B树.它与红黑树有许多类似的地方,比如都是平衡搜索树,但它们在功能和结构上却有较大的差别. 从功能上看,B树是为磁盘或其他存储设备设计的, ...

  2. 分布式系列文章——Paxos算法原理与推导

    Paxos算法在分布式领域具有非常重要的地位.但是Paxos算法有两个比较明显的缺点:1.难以理解 2.工程实现更难. 网上有很多讲解Paxos算法的文章,但是质量参差不齐.看了很多关于Paxos的资 ...

  3. 【Machine Learning】KNN算法虹膜图片识别

    K-近邻算法虹膜图片识别实战 作者:白宁超 2017年1月3日18:26:33 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  4. 红黑树——算法导论(15)

    1. 什么是红黑树 (1) 简介     上一篇我们介绍了基本动态集合操作时间复杂度均为O(h)的二叉搜索树.但遗憾的是,只有当二叉搜索树高度较低时,这些集合操作才会较快:即当树的高度较高(甚至一种极 ...

  5. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  6. 虚拟dom与diff算法 分析

    好文集合: 深入浅出React(四):虚拟DOM Diff算法解析 全面理解虚拟DOM,实现虚拟DOM

  7. 简单有效的kmp算法

    以前看过kmp算法,当时接触后总感觉好深奥啊,抱着数据结构的数啃了一中午,最终才大致看懂,后来提起kmp也只剩下“奥,它是做模式匹配的”这点干货.最近有空,翻出来算法导论看看,原来就是这么简单(先不说 ...

  8. 神经网络、logistic回归等分类算法简单实现

    最近在github上看到一个很有趣的项目,通过文本训练可以让计算机写出特定风格的文章,有人就专门写了一个小项目生成汪峰风格的歌词.看完后有一些自己的小想法,也想做一个玩儿一玩儿.用到的原理是深度学习里 ...

  9. 46张PPT讲述JVM体系结构、GC算法和调优

    本PPT从JVM体系结构概述.GC算法.Hotspot内存管理.Hotspot垃圾回收器.调优和监控工具六大方面进行讲述.(内嵌iframe,建议使用电脑浏览) 好东西当然要分享,PPT已上传可供下载 ...

随机推荐

  1. 剑指offer-面试题6-从头到尾打印链表-链表

    /* 题目: 输入一个链表的头节点,从尾到头反过来打印每个节点的值 */ /* 思路: 解法一:利用栈后进先出的特性. 解法二:利用递归函数的性质. */ void PrintListReversin ...

  2. gulp常用插件之gulp-plumber使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-plumber这是一款防止因gulp插件的错误而导致管道中断,plumber可以阻止 gulp 插件发生错误导致进程退出并输出错误日志. ...

  3. http中长连接和websocket的长连接的区别

    一.什么是http协议 HTTP是一个应用层协议,无状态的,端口号为80.主要的版本有1.0/1.1/2.0.   HTTP/1.* 一次请求-响应,建立一个连接,用完关闭: HTTP/1.1 串行化 ...

  4. go append 函数常见操作

    1. 将切片 b 的元素追加到切片 a 之后: a = append(a, b...) 2. 复制切片 a 的元素到新的切片 b 上: 1. b = make([]T, len(a)) 2. copy ...

  5. koa文档笔记

    请求 get ctx.request.query // 查询对象 ctx.request.querystring // 查询字符串 ctx.query // 查询对象 ctx.querystring ...

  6. Ioc依赖注入:Unity4.0.1 在项目中的应用 (MVC和API)

    使用Unity的好处网上有很多,百度一下即可 这里引用了一篇关于面向接口编程的好处的文章作为引申:https://blog.csdn.net/Cyy19970527/article/details/8 ...

  7. UTF自动化测试工具

    自UFT推出后,QTP慢慢退出历史舞台 UFT测试的基本流程:录制测试脚本—-编辑测试脚本—-调试测试脚本—-运行测试脚本—-分析测试结果 UFT(QTP)介绍   http://blog.csdn. ...

  8. TCL常用命令

    1.删除文件 file delete A file delete -force A 2.建立文件夹 file mkdir A file mkdir A/A 3.判断文件夹是否存在 file exist ...

  9. Day5 多线程 锁

    synchronized保证操作原子性 这是因为对变量进行读取和写入时,结果要正确,必须保证是原子操作.原子操作是指不能被中断的一个或一系列操作. 通过加锁和解锁的操作,就能保证3条指令总是在一个线程 ...

  10. 机器学习作业(四)神经网络参数的拟合——Python(numpy)实现

    题目下载[传送门] 题目简述:识别图片中的数字,训练该模型,求参数θ. 出现了一个问题:虽然训练的模型能够有很好的预测准确率,但是使用minimize函数时候始终无法成功,无论设计的迭代次数有多大,如 ...