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 ...
随机推荐
- jquery indexOf使用方法
当无法确定在某个字符串中是否确实存在一个字符的时候,就可调用 indexOf() 和 lastIndexOf() 方法 indexOf() 和 lastIndexOf() 是js的用法,与jquery ...
- bootstrap table简洁扁平的表格
使用方法 1.在html页面的head标签中引入Bootstrap库(假如你的项目还没使用)和bootstrap-table.css. <link rel="stylesheet&qu ...
- FatMouse的交易问题
想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...
- HD2444The Accomodation of Students(并查集判断二分图+匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- ExtJS入门教程05,grid的异步加载数据
上一篇演示了extjs grid的基本用法,并加载了本地数据.今天我们将演示如何加载异步数据. 所谓异步,就是通过ajax的方式将服务器端的数据加载到我们的grid中.为了提供数据,我们先定义一个数据 ...
- Appserv环境下搭建的PHP环境升级PHP版本(支持微信端口以及thinkphp)
Appserv 2.5.10 升级PHP from version 5.2 to 5.3 最近,在使用Appserv 2.5.10 中的PHP开发微信时,遇到下面错误 Fatal error C ...
- 解决微信OAuth2.0网页授权回调域名只能设置一个的问题
https://github.com/HADB/GetWeixinCode GetWeixinCode 解决微信OAuth2.0网页授权回调域名只能设置一个的问题 使用方法 部署get-weixin- ...
- 如何使用网盘托管git项目
话说近年来git已经成为项目源代码管理的标准工具,有不少免费托管网站可供使用,详情参考这篇文章: http://www.cnblogs.com/zdz8207/archive/2012/05/20/2 ...
- Repository
namespace MyRepository.Domain.Infrastructure { public class Repository<TEntity> : IRepository& ...
- ASP.NET MVC4中使用Ninject
1.NuGet获取Ninject.dll 选中项目右键: .NET技术交流群 199281001 .欢迎加入. 2.全局注册 Global.asax.cs //注册Ninject依赖注入全局解析器 ...