HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2017-04-13)
Description
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
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
Sample Input
Sample Output
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[],f[];
int main()
{
int n;
while(~scanf("%d",&n))
{
if(!n)
break;
memset(a,,sizeof(a));
for(int i=;i<n;i++)
scanf("%d",&a[i]);
int maxn = ;
for(int i=;i<n;i++)
{
f[i] = a[i];//先给每个f[i]附一个本身的值
for(int j=i-;j>=;j--)
{
if(a[i]>a[j]&&a[i]+f[j]>f[i])//从a[i]的前面找出比a[i]小的
f[i] = a[i] + f[j];//然后dp每个f[i]
}//注意 4 3 2 1 3 结果为5 递增序列为 2 3
}
for(int j=n-;j>=;j--)
{
if(maxn < f[j])
maxn = f[j];
}
printf("%d\n",maxn);
}
return ;
}
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[],a[];
int main(){
int n;
while(cin >> n){
if(!n){
break;
}
for(int i=;i<=n;i++){
cin >> a[i];
}
memset(dp,,sizeof(dp));
int ans = ;
for(int i=;i<=n;i++){//注意这里从一开始的
for(int j=;j<i;j++){
if(a[j]<a[i])
dp[i] = max(dp[i],dp[j]+a[i]);
//因为a数组从一开始的,所以dp[0]永远为0,这样比较时,j=0时可以与a[i]比较大小
}
ans = max(ans,dp[i]);
}
cout << ans << endl;
}
return ;
}
HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *的更多相关文章
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- 最长上升子序列模板 hdu 1087 Super Jumping! Jumping! Jumping!
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
- 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!
来源:点击打开链接 最长上升子序列的考察,是一个简单的DP问题.我们每一次求出从第一个数到当前这个数的最长上升子序列,直至遍历到最后一个数字为止,然后再取dp数组里最大的那个即为整个序列的最长上升子序 ...
- HDU - 1087 Super Jumping!Jumping!Jumping!(dp求最长上升子序列的和)
传送门:HDU_1087 题意:现在要玩一个跳棋类游戏,有棋盘和棋子.从棋子st开始,跳到棋子en结束.跳动棋子的规则是下一个落脚的棋子的号码必须要大于当前棋子的号码.st的号是所有棋子中最小的,en ...
- hdu 1087 Super Jumping!(类最长上升子序列)
题意:在一组数中选取一个上升子序列,使得这个子序列的和最大. 解:和最长上升子序列dp过程相似,设dp[i]为以第i位为结尾最大和,那么dp[i]等于max(dp[0],dp[1],,,,,dp[i- ...
- 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 ...
- HDU 1087 Super Jumping! Jumping! Jumping! (动态规划、最大上升子序列和)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
随机推荐
- UE4 游戏模块初始化顺序
最近看教学,有个讲解UE4初始化顺序的,记录一下. 首先创建一个Actor,Character,GameInstance,GameMode,LevelScriptActor(关卡),PlayerCon ...
- 设置Myeclipse的jvm内存参数
Myeclipse经常会遇到内存溢出和Gc开销过大的情况,这时候就需要修改Myeclipse的Jvm内存参数 修改如下:(使用Extjs做公司大项目时候,不要让项目Builders的Javascrip ...
- JAVA基础——Switch条件语句
JAVA基础——switch 条件语句 switch语句结构: switch(表达式){ case值1: 语句体1: break: case值2: 语句体2: break: case值3: 语句体3: ...
- git常用指令整理
git常用指令一览表 GIT指令 说明 git add . 将全部文件的内容加到Git索引以便执行commit. 这个指令不会检查文件夹中是否有文件被删除. 要注意的是,只有执行" git ...
- HTML之必备meta标签
meta标签写在HTML的<head>中,推荐每个手机H5页面必加以下的代码: <head> <meta charset="UTF-8"> &l ...
- html学习笔记整理
网页 1.网页的组成部分 网页是由文字,图片,视频,音频,输入框,按钮这些元素(也就是html标签)组成. 2.浏览网页常用的五大主流浏览器 谷歌,IE,火狐,欧朋,safari.浏览器的内核(渲染引 ...
- SIMBOSS:物联网业务如何应用领域驱动设计?
前言 在这个万物互联的时代,物联网业务蓬勃发展,但也瞬息万变,对于开发人员来说,这是一种挑战,但也是一种“折磨”. 在业务发展初期,因为时间有限,我们一般会遵循“小步快跑,迭代试错”的原则进行业务开发 ...
- 从0到1发布一个npm包
从0到1发布一个npm包 author: @TiffanysBear 最近在项目业务中有遇到一些问题,一些通用的方法或者封装的模块在PC.WAP甚至是APP中都需要使用,但是对于业务的PC.WAP.A ...
- Goland_IDE的护眼、主题、字体等设置
Goland_IDE的护眼.主题.字体等设置 1.代码格式化 File->Settings->Tools->File Watchers->+->go fmt->将N ...
- IoT时代:Wi-Fi“配网”技术剖析总结
导读 近年来,物联网市场竞争激烈,从物联网平台厂商,设备生产商,到服务提供商,都在涌入这片红海.预计到2020年,全球联网设备数量将达到260亿个,年复合增长率达到20%:全球联网设备带来的数据将达到 ...