HDU 1087 Super Jumping! Jumping! Jumping! (DP)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
4 1 2 3 4
4 3 3 2 1
0
Sample Output
10
3
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1005 int main(void)
{
int n;
int s[MAX];
int dp[MAX],max,ans; //dp[i]存的是以i为起点的最大升序子串的和 while(scanf("%d",&n) && n)
{
for(int i = ;i < n;i ++)
scanf("%d",&s[i]); ans = dp[n - ] = s[n - ];
for(int i = n - ;i >= ;i --)
{
max = ;
for(int j = i + ;j < n;j ++) //看s[i]后面哪一个子串是s[i]可以加进去的,找出所有这样的子串,取DP值最大那个
if(s[i] < s[j] && max < dp[j])
max = dp[j];
dp[i] = s[i] + max; ans = ans < dp[i] ? dp[i] : ans;
}
ans = ans < ? : ans; //注意可以从起点直接跳终点,此时值为0,若是算出最终值是负数的话要选此方案 printf("%d\n",ans);
} return ;
}
HDU 1087 Super Jumping! Jumping! Jumping! (DP)的更多相关文章
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- 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!(求LSI序列元素的和,改一下LIS转移方程)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...
- 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 ...
- HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)
Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!&quo ...
- HDU 1087 Super Jumping! Jumping! Jumping!【DP】
解题思路:题目的大意是给出一列数,求这列数里面最长递增数列的和 dp[i]表示到达地点i的最大值,那么是如何达到i的呢,则我们可以考虑没有限制条件时候的跳跃,即可以从第1,2,3,---,i-1个地点 ...
随机推荐
- php中定义类
<?php class Person{ //定义了一个Person类 public $name; //定义属性name public $age; //定义属性age function __con ...
- UI:基础
App的生命周期 参考 多态的使用 // // main.m #import <Foundation/Foundation.h> #import "SingleDog.h&quo ...
- win8下hosts保存文档失败,提示:请检查文件是否被另一个应用程序打开
选择文件,然后右键点击属性,然后进入"安全"选项卡下点击当前用户对用的用户名然后编辑权限,给予完全控制的权限. 如图: 图一:
- HITAG 1/2/S
HITAG S -- 3rd generation HITAG™ family Modulation Read/Write Device to Transponder: 100 % ASK and B ...
- uva387 - A Puzzling Problem
A Puzzling Problem The goal of this problem is to write a program which will take from 1 to 5 puzzle ...
- PL/pgSQL学习笔记之四
http://www.postgresql.org/docs/9.1/static/plpgsql-structure.html 39.2. PL/pgSQL 的结构 PL/pgSQL是一种块式结构的 ...
- Codeforces Round #309 (Div. 1) C. Love Triangles dfs
C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/pro ...
- C# 图片裁剪代码
/// <summary> /// 缩小裁剪图片 /// </summary> /// <param name="int_Width">要缩小裁 ...
- C# API: 生成和读取Excel文件
我们想为用户提供一些数据,考虑再三, 大家认为对于用户(人,而非机器)的可读性, Excel文件要好一些. 因为相比csv,xml等文件, Excel中我们可以运用自动筛选, 窗口锁定, 还可以控制背 ...
- JS的注意点
JS的跨域访问问题. http://www.cnblogs.com/rush/archive/2012/05/15/2502264.html JS能操作的范围:HTTP协议的内容.但是不能直接访问re ...