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. BZOJ#2121. 字符串游戏 [区间dp]

    // powered by c++11 // by Isaunoya #include<bits/stdc++.h> #define rep(i , x , y) for(register ...

  2. bugku-求getshell(文件上传)

    这道题最主要是考的Content-type参数绕过WAF,然后利用绕过黑名单上传php进行解析. 先上传一个phpinfo()的php文件试试,burp抓包 正常操作,先将下面文件的类型改为:imag ...

  3. 安装Elasticsearch到Linux(源码)

    运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:Elasticsearch-7.1.0 硬件要求:最低2核4GB 安装过程 1.源码安装JDK ...

  4. laravel本地化扩展包的下载使用

    1.下载扩展包 composer require caouecs/laravel-lang:~3.0 2.下载完成之后在根目录下的vendor中caouces\src下就是语言的扩展包 2.1我们复制 ...

  5. 二叉堆(3)SkewHeap

    斜堆. 测试文件 main.cpp: #include <iostream> #include "SkewHeap.h" using std::cout; using ...

  6. 曼孚科技:AI自然语言处理(NLP)领域常用的16个术语

    ​自然语言处理(NLP)是人工智能领域一个十分重要的研究方向.NLP研究的是实现人与计算机之间用自然语言进行有效沟通的各种理论与方法. 本文整理了NLP领域常用的16个术语,希望可以帮助大家更好地理解 ...

  7. 从servlet向jsp中传数据用Java接收js调用

    servlet: response.sendRedirect("showMessage.jsp?ValueA=1"); jsp: var a=<%=request.getPa ...

  8. 在VMware下安装CentOS 7.6

    转载自https://blog.51cto.com/hnyuanzijian/2343716?appinstall=0a.点击左上角文件,新建虚拟机,选择典型安装,并下一步   b.选择稍后安装操作系 ...

  9. PP: Robust Anomaly Detection for Multivariate Time Series through Stochastic Recurrent Neural Network

    PROBLEM: OmniAnomaly multivariate time series anomaly detection + unsupervised 主体思想: input: multivar ...

  10. C++中局部变量的返回

    在写 “根据中序和后序遍历顺序,构建树的问题” 时,原本这只是一个非常简单的问题,但是突然发现一直有错误.代码如下: node* get_root(int x1, int x2, int y1, in ...