HDU-1087Super Jumping! Jumping! Jumping!
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000
MS (Java/Others)
Memory Limit: 65536/32768
K (Java/Others)

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.
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.
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
4
10
3
题目意思很好懂,但所给的测试样例太水(hdu上的样例都是这样),以为要用最长单调递增子序列,但一直没有好的思路,,后来TJY小田想出了一个很好的思路;就是用两层循环,一层输入,一层查询,只要输入的数据其前面的数据满足条件,就直接用另外一个数组相加储存最大和,那么,,需要满足什么条件呢:
请看样例:
4 1 2 3 4;输出10,1前面没有谁比他小,故1的位置就是1,而2前面有1,故2的位置是3,同理3的位置是6,4的位置是10,看出来了吧,前面的数据小就加起来;
再看这组数据:
5 1 3 2 5 6 ;输出是15,这组应该没什么问题;
6 4 9 6 8 5 10;输出28,来分析看,9的位置是13,而6的位置是10,8的位置是18,5的位置是9,10的位置是28;
只要前面的数据比当前数据小就加起来;
但 7 4 9 2 6 8 5 10;输出应该是28,用刚刚的方法就不行了,因为2这个数据很小,后面的数据都会加上它 ,而实际上它是不算在递增序列中的,所以,,看代码:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1000+10;
int a[N],c[N];
int main()
{
int n,i,j,k;
while(scanf("%d",&n)&&n)
{
memset(c,0,sizeof(c));
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
c[i]=a[i],k=0;
for(j=1; j<i; j++)
{
if(a[j]<a[i])
c[i]=max(c[i],a[i]+c[j]);//手推上面的样例就会明白的;
}
}
sort(c+1,c+n+1);
printf("%d\n",c[n]);
}
return 0;
}
HDU-1087Super Jumping! Jumping! Jumping!的更多相关文章
- HDU 1087:Super Jumping! Jumping! Jumping!(LIS)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 【HDU - 1087 】Super Jumping! Jumping! Jumping! (简单dp)
Super Jumping! Jumping! Jumping! 搬中文ing Descriptions: wsw成功的在zzq的帮助下获得了与小姐姐约会的机会,同时也不用担心wls会发现了,可是如何 ...
- HDU 1087 E - Super Jumping! Jumping! Jumping! DP
http://acm.hdu.edu.cn/showproblem.php?pid=1087 设dp[i]表示去到这个位置时的最大和值.(就是以第i个为结尾的时候的最大值) 那么只要扫描一遍dp数组, ...
- HDU - 1087 Super Jumping!Jumping!Jumping!(dp求最长上升子序列的和)
传送门:HDU_1087 题意:现在要玩一个跳棋类游戏,有棋盘和棋子.从棋子st开始,跳到棋子en结束.跳动棋子的规则是下一个落脚的棋子的号码必须要大于当前棋子的号码.st的号是所有棋子中最小的,en ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- hdu 1155 Bungee Jumping
http://acm.hdu.edu.cn/showproblem.php?pid=1155 Bungee Jumping Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1087 Super Jumping! Jumping! Jumping! (DP)
C - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
随机推荐
- rhel 6.5--samba
配置匿名共享: 服务端: [root@master ~]# yum install -y samba 或者 [root@master ~]# yum groupinstall -y "CIF ...
- json字符串和字典类型的相互转换
在开发过程中,有时候需要将json字符串转为字典类型,反之亦然,通常采用.Net的开源类库Newtonsoft.Json进行序列化,这里我也是采用这个,不过我更喜欢写扩展方法方便在项目的调用. 首先新 ...
- AJPFX关于一维数组的声明与初始化
一维数组:可以理解为一列多行.类型相同的数据,其中每个数据被称为数组元素:一维数组的声明方式: type varName[]; 或 type[] varName;(推荐) ...
- (4)《Head First HTML与CSS》学习笔记---文本的CSS规则和盒模型;div与span;<a>元素的链接色;伪类
1.每个font-family包含一组共同特征的字体.共五个字体系列: sans-serif----这个系列包括了没有衬线的字体,与serif相比,通常认为这个系列更容易在计算机上识读. serif- ...
- git 配置免密上传,配置ssh key
1.windows 打开git bash 控制台,linux 直接打开命令控制台,输入 ssh-keygen 一直enter 下一步 2.生成的文件windows 存放在c://users 路径下,l ...
- Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission denied
Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission den ...
- CSS3实现单行、多行文本溢出(省略号的形式出现)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Python3 OpenCV3 图像处理基础
开发环境搭建 本人使用的是Ubuntu 16.04LTS. 1.安装Python3 ## 其实 Ubuntu 16.04 系统自带了 Python 3.5.2,因此不需要再安装了?但是需要安装一些开发 ...
- libs/tools.js stringToDate dateToString 日期字符串转换函数
libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js' e ...
- 清空表单方法 清空变量 iview modal
方法一 通过json序列号和反序列号 清空一次数据 数据需要copy出来一份 orgFormClearAllInput () { this.$refs.n1.formValidate = JSON.p ...