dp --A - Super Jumping! Jumping! Jumping!
A - Super Jumping! Jumping! Jumping!
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.InputInput 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.
OutputFor each case, print the maximum according to rules, and one line one case.
Sample Input3 1 3 2
4 1 2 3 4
4 3 3 2 1
0Sample Output
4
10
3
题目大意:求升序子序列的最大和
#include<bits/stdc++.h>
using namespace std; int dp[];//dp用于存放从数组头到此为止的最大升序子序列和
int n, a[];
int maxn; int main(){
while(~scanf("%d", &n) && n){
maxn = ;
for(int i=; i<n; i++){
scanf("%d", a+i);
dp[i] = a[i];//将每个ai的值赋予dpi
}
for(int i=; i<n; i++){
for(int j=; j<i; j++){
if(a[i] > a[j] && dp[i] < dp[j]+a[i])
dp[i] = dp[j] + a[i];
if(dp[i] > maxn) maxn = dp[i];
}
} printf("%d\n",maxn);
}
}
是今天刚学的dp,告诉我们这类题目没有固定的模板,更重要的是思维和思考,借助dp这样的一个数组,去存放你需要求或相关的变量。既然没有固定模板,则需要更多的练习,去接触更多样式的巧妙的题目
dp --A - Super Jumping! Jumping! Jumping!的更多相关文章
- 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! (DP)
C - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)
Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!&quo ...
- Super Jumping! Jumping! Jumping!(dp)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU1087:Super Jumping! Jumping! Jumping!(DP)
Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...
- 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!(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...
随机推荐
- 软件质量保障初探_Chris
关于软件质量保障的体会 首先,软件质量保障的重要性不言而喻,书中说软件质量体现在以下方面 软件开发过程的可见性 软件开发过程的风险控制 软件内部模块,项目中间阶段的交付质量,项目管理工具的因素 软件开 ...
- logstash split插件的使用(将一个事件拆分成多个事件)
kafka中的原始数据格式(1条数据) { "body": { "cwd": "/home/test/", "monitor&qu ...
- React+Echarts简单的封装套路
今天我们来介绍一下React中,对Echarts的一个简单的封装. 首先在我们的React项目中,想使用Echart包,首先需要先安装它,安装代码如下,任选一个就可以 cnpm install ech ...
- html input元素的所有type属性
<input /> 属性 type="text" 输入框的类型为文本 type="password" 输入框的类型为密码 type="ra ...
- 开源堡垒机jumpserver
开源堡垒机jumpserver 开源堡垒机jumpserver的安装 开源堡垒机jumpserver的配置和使用
- 多图预警——从 RAID 到分布式系统中的副本分布
原文首发于个人博客「tobe的呓语」欢迎大家的访问收藏啊~ 我们知道,在面对大规模数据的计算和存储时,有两种处理思路: 垂直扩展(scale up):通过升级单机的硬件,如 CPU.内存.磁盘等,提高 ...
- Day6前端学习之路——布局
一.定位 1)静态定位 position:static(默认) 2)相对定位 position:relative(要配合top.bottom.left.right等属性来使用) 3)绝对定位 pos ...
- 关键两步+6个要点,让Windows应用程序享有K8S的绝佳优势
本文来自Rancher Labs 前 言 实际上,没有一个迁移路径能够适用于将所有传统应用程序迁移到云.这些应用程序通常在物理机.虚拟机或本地.虽然一般情况下是重新设计应用程序架构以适用云原生服务, ...
- 细读jsr中的yield语义,或者不是我们想象中的那样
这只是我的个人观点,如有错误,希望你可以指出. 首先英文原版 中文译版 我觉得“不需要”还会让人产生误解,应该译为不一定要. 很多时候会被断章取义地理解,我们一定要有“不一定”,“可能”的意识,下面给 ...
- 移动app
什么是移动App开发[重点] 苹果上的软件是如何开发出来的:使用IOS平台的开发工具和开发语言进行设计开发的!苹果上的开发语言:OC.Swift 安卓平台上的软件又是如何开发出来的:使用Java这么语 ...