HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32564 Accepted Submission(s):
14692
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.
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.
and one line one case.
4 1 2 3 4
4 3 3 2 1
0
下标i | 0 | 1 | 2 | 3 | 4 | 5 |
a[i] | ||||||
sum[i] | 3 | 2 | 7 | 2 | 5 | 13 |
ans | 0 | 3 | 7 | 7 | 5 | 13 |
#include <iostream>
#include <cstdio>
//#define max(a,b) a>b ? a:b
using namespace std; int main()
{
int n;
int a[];//存储每一个数
int sum[];//存储这个数之前的递增子序列的和
int ans;//一直存储最大的和
while(scanf("%d",&n)!=EOF && n!=){
for(int j1=;j1<n;j1++){
scanf("%d",&a[j1]);
}
sum[]=a[];
ans=;
for(int i= ;i<n;i++){
ans=;
for(int j=;j<i;j++){
if(a[i]>a[j]){
ans=max(sum[j],ans);//重要代码!
}
}
sum[i]=a[i]+ans;//重要代码!
}
ans=-;
for(int i=;i<n;i++){
if(ans<sum[i]){
ans=sum[i];
}
}
cout<<ans<<endl;
}
return ;
}
我是代码,请点我!!!
不懂的时候,告诉自己,再坚持一下,再坚持一下,这个题就看懂了。
刚开始不会做,然后百度,看了好久才看明白这个题的方法~~~~(>_<)~~~~
HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列的更多相关文章
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- HDU 1257 最少拦截系统 最长递增子序列
HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...
- HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)
Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!&quo ...
- 题解报告:hdu 1087 Super Jumping! Jumping! Jumping!
Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划)
题意: 求解最大递增子序列. 例如:3 1 3 2 输入 3 个数 1 3 2 则递增子序列有 {1} {3} {2} {1 3} {1 2} ,故输出子序列的最大和 4 解题思路: x[n](n个 ...
- HDU 1087 Super Jumping....(动态规划之最大递增子序列和)
Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...
随机推荐
- 【CodeForces 599A】D - 特别水的题4- Patrick and Shopping
Description meter long road between his house and the first shop and a d2 meter long road between h ...
- golang thrift 源码分析,服务器和客户端究竟是如何工作的
首先编写thrift文件(rpcserver.thrift),运行thrift --gen go rpcserver.thrift,生成代码 namespace go rpc service RpcS ...
- IPC机制
转:http://blog.chinaunix.net/uid-26125381-id-3206237.html IPC 三种通信机制 2012-05-13 17:23:55 最近看了,IPC三种通 ...
- HackerRank and MiniMax
传送门 Sherlock and MiniMax Authored by darkshadows on May 07 2014 Problem Statement Watson gives Sherl ...
- HD1580(尼姆博弈入门)
启蒙博客:http://www.cnblogs.com/jiangjun/archive/2012/11/01/2749937.html 尼姆博奕(Nimm Game):有三堆各若干个物品,两个人轮流 ...
- Hbase Shell常用命令
hbase shell常用的操作命令有create,describe,disable,drop,list,scan,put,get,delete,deleteall,count,status等,通过h ...
- 使用I/O 系统调用--copy.c
作为Linux/Unix 系统编程入门,小生按照自己可以理解的方式,改写了源copy.c源代码来自:Linux/UNIX 系统编程手册 上册 P57 #include <stdio.h>/ ...
- block中防止循环引用的一个高大上的宏定义
看惯了什么tempSelf weakSelf,来点高大的 #define weakify(...) \ rac_keywordify \ metamacro_foreach_cxt(rac_weaki ...
- 如果jsp提交到action为空指针的话
很严重的一点:表单<form>有没有添加一个method="post",如果表单的这个没有写,肯定是空指针, 哎,被这个坑爹的代码,查了好久,特此记录下
- 15个超实用的php正则表达式
在这篇文章里,我已经编写了15个超有用的正则表达式,WEB开发人员都应该将它收藏到自己的工具包. 验证域名 检验一个字符串是否是个有效域名. $url = "http://komunitas ...