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 ...
随机推荐
- eclipse导入项目时的一些准备
导入前的工作: 1.因为别人项目的运行环境可能和我们不一样,所以首先要在要导入的项目里面找到.setting文件,修改下面的xml文件,这个文件里面是关于服务器的一些配置的信息,你可以改成与你电脑一样 ...
- spring mvc框架入门
目录 1.web框架分层 2.什么是springmvc 3.springmvc的优势 4.springmvc和struct的区别 (spring mvc框架入门 1.web框架分层 一般web框架可以 ...
- mongodb 常用操作命令
1.关闭mongodbuse admindb.shutdownServer() 2.报错 not master and slaveok=falsers.slaveOk(); 3.查看集群副本的状态rs ...
- win10系统下安装JDK1.8及配置环境变量的方法
本次演示基于windows10操作系统,如果你是linux,请参考:https://www.yn2333.com/archives/linux上安装JDK8 1:下载安装包 地址:https://ww ...
- centos下利用phantomjs来完成网站页面快照截图
最近研究了下phantomjs,感觉还是非常不错的. 首先到官网下载一个源码包 http://phantomjs.org/download.html 点击源码包下载如图: 然后在linux下将必要的一 ...
- 当前行的td值传入模态框
<!-- 让include引用的页面,因为故障列表和周.月故障列表里面的table和分页是一样的前端页面,只有一点不同,没必要每个页面都写这些 --> <table id=" ...
- Linux恢复删除的文件
linux恢复删除的文件 先介绍下一些文件的基本概念: · 文件实际上是一个指向inode的链接, inode链接包含了文件的所有属性, 比如权限和所有者, 数据块地址(文件存储在磁盘 ...
- 大数四则运算之减法运算-----c语言版
/* 分三种情况: 1.减数长度大于被减数 交换减数与被减数,输出负号,方便减 2.减数长度等于被减数(分三种情况) a.减数大于被减数,类似1情况1 b.减数等于被减数,两数相等,直接输出0,完成. ...
- Qt Python Scriptable Application
Qt Python Scriptable Application eryar@163.com Abstract. Python and C++ are in many ways as differen ...
- 使用A线程打印1-52,B线程打印A-Z,要求按照12A34B56C....5152Z的顺序进行交替打印
多线程同步问题,都需要用到监视器,用来监视资源是否可用.C++中使用condition_variable,Java中使用Condition来实现同步. 1. 实现思路 需要有一个全局变量控制当前该哪个 ...