Super Jumping! Jumping! Jumping!

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2017-04-13)

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
 
求最长连续递增序列的和
#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 ;
}
 在加一种dp方法,这种dp更简单
#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! 最长递增子序列(求可能的递增序列的和的最大值) *的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping

    HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...

  2. 最长上升子序列模板 hdu 1087 Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...

  3. 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!

    来源:点击打开链接 最长上升子序列的考察,是一个简单的DP问题.我们每一次求出从第一个数到当前这个数的最长上升子序列,直至遍历到最后一个数字为止,然后再取dp数组里最大的那个即为整个序列的最长上升子序 ...

  4. HDU - 1087 Super Jumping!Jumping!Jumping!(dp求最长上升子序列的和)

    传送门:HDU_1087 题意:现在要玩一个跳棋类游戏,有棋盘和棋子.从棋子st开始,跳到棋子en结束.跳动棋子的规则是下一个落脚的棋子的号码必须要大于当前棋子的号码.st的号是所有棋子中最小的,en ...

  5. hdu 1087 Super Jumping!(类最长上升子序列)

    题意:在一组数中选取一个上升子序列,使得这个子序列的和最大. 解:和最长上升子序列dp过程相似,设dp[i]为以第i位为结尾最大和,那么dp[i]等于max(dp[0],dp[1],,,,,dp[i- ...

  6. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...

  7. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...

  8. HDU 1087 Super Jumping! Jumping! Jumping! (动态规划、最大上升子序列和)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

随机推荐

  1. lvs+keepalived 高可用及负载均衡

    一.环境准备 VIP:10.18.43.30 dr1:10.18.43.10 dr2:10.18.43.20 web1:10.18.43.13 web2:10.18.43.14 结构图 (一).预处理 ...

  2. macOS 安装配置yaf框架 生成yaf项目

    macOS 安装配置yaf框架 Yaf只支持PHP5.2及以上的版本. 并支持最新的PHP5.3.3 Yaf需要SPL的支持. SPL在PHP5中是默认启用的扩展模块 Yaf需要PCRE的支持. PC ...

  3. .Net Core in Docker - 使用阿里云Codepipeline及阿里云容器镜像服务实现持续集成(CI)

    前面已经介绍过了 .Net Core 程序发布到 Docker 容器的内容.但是每次通过 SSH 链接到服务器敲命令,运行脚本也是挺麻烦的一件事.程序员是最懒的,能让电脑解决的问题绝不手动解决,如果当 ...

  4. Python Iterator and Generator

    Python Iterator and Generator Iterator ​ 迭代器(Iterator)和可迭代对象(Iterable)往往是绑定的.可迭代对象就是我们平时经常用的list ,st ...

  5. Kafka基本知识入门(一)

    1. 基础知识 有关RabbitMQ,RocketMQ,Kafka的区别这个网上很多,了解一下区别性能,分清什么场景使用.分布式环境下的消息中间件Kafka做的比较不错,在分布式环境下使用频繁,我也不 ...

  6. 关于Oracle本地连接出现与监听有关的问题的解决方法探讨

    关于Oracle本地连接出现与监听有关的问题的解决方法探讨 监听的作用: 用于应用桌面即用户与数据库服务器建立连接的媒介,客户端发送连接请求,监听识别请求并建立客户端与服务器的连接后,监听的使命并完成 ...

  7. TCP/UDP对比总结

    目录 1 TCP-UDP对比 2 UDP介绍 3 TCP介绍 3.1 可靠传输的原理和实现 3.1.1 可靠传输原理 3.1.2 可靠传输实现 3.2 TCP面向连接管理 3.2.1 建立连接 3.2 ...

  8. postman-使用教程

    postman postman是一款非常方便的API测试工具,可以帮我们快速的发起HTTP请求,下面记录一下postman的基本使用. postman安装 postman下载地址 下载安装打开之后就是 ...

  9. 《机器学习基石》---Linear Models for Classification

    1 用回归来做分类 到目前为止,我们学习了线性分类,线性回归,逻辑回归这三种模型.以下是它们的pointwise损失函数对比(为了更容易对比,都把它们写作s和y的函数,s是wTx,表示线性打分的分数) ...

  10. k8s学习笔记

    9.deployment:声明式的升级应用 9.1.使用RC实现滚动升级 #kubectl rolling-update kubia-v1 kubia-v2 --image=luksa/kubia:v ...