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. cin,cin.get(),cin.getline(),gets(),getchar()函数的用法

    1.cin>> 用法a:最基本的流输入用法,接受一个数字或字符,自动跳过输入的空格. 用法b:接受一个字符串,但是遇到除开头外的空格则会终止输入. #include<iostream ...

  2. 安装APACHE到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:httpd-2.4.6 硬件要求:无 安装过程 1.安装YUM-EPEL源 HTTP-Tools ...

  3. java回文代码

    import java.util.*; import java.math.BigInteger; import java.util.Scanner; public class Test{ static ...

  4. Docker 使用记录

    1.Docker 镜像加载本地镜像 2.Docker 创建镜像: 创建dockerfile 文件: 进入到文件目录下: 输入命令 docker build -t xxxx . 注意:后面的小点要有, ...

  5. Docker最全教程——从理论到实战(十八)

    前言 VS Code是一个年轻的编辑器,但是确实是非常犀利.通过本篇,老司机带你使用VS Code玩转Docker——相信阅读本篇之后,无论是初学者还是老手,都可以非常方便的玩转Docker了!所谓是 ...

  6. GNU Screen使用

    基本使用 SSH时可以方便地resume工作 # open new screen session screen # restore screen -r  Steps Using GNU Screen ...

  7. JS使用知识点理解

    var keyValue = $.request("keyValue"); $(function () { ////修改页面select下拉选框js $("#BloodB ...

  8. PHP中关于foreach使用引用变量的坑

    PHP版本为 5.6.12 代码如下:   1 2 3 4 5 6 7 8 9 10 11 12 <?php $arr = ['a', 'b', 'c', 'd', 'e']; foreach ...

  9. webpack 之搭建本地服务器

    搭建本地服务器 webpack提供了一个可选的本地开发服务器,这个本地服务器基于node.js搭建,内部使用express框架,可以实现 我们想要的让浏览器自动刷新显示我们修改后的结果 不过它是一个单 ...

  10. python调用HEG工具批量处理MODIS数据

    下面的代码主要用于使用python语言调用NASA官方的MODIS处理工具HEG进行投影坐标转换与重采样批量处理 主要参考 HEG的用户手册:https://newsroom.gsfc.nasa.go ...