博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1087——Super Jumping! Jumping! Jumping!(最大递增子序列和)
阅读量:2343 次
发布时间:2019-05-10

本文共 2214 字,大约阅读时间需要 7 分钟。

Problem 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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 110000#define Mod 10001using namespace std;int a[MAXN],dp[MAXN];int main(){ int n; while(~scanf("%d",&n)&&n) { int ans; memset(dp,0,sizeof(dp)); for(int i=1; i<=n; ++i) scanf("%d",&a[i]); for(int i=1; i<=n; ++i) { ans=-INF; for(int j=0; j
a[j]) ans=max(ans,dp[j]); } dp[i]=ans+a[i]; } ans=-INF; for(int i=1; i<=n; ++i) ans=max(ans,dp[i]); printf("%d\n",ans); } return 0;}

转载地址:http://ctcvb.baihongyu.com/

你可能感兴趣的文章
JQuery+JQuery ui实现的弹出窗口
查看>>
jQuery怎么获取<c:forEach>标签的值
查看>>
程序员应该知道的福利
查看>>
Java日期时间处理
查看>>
包装类
查看>>
Object/System/RunTime类
查看>>
字符串类/正则表达式
查看>>
看完不敢熬夜了
查看>>
Java异常处理
查看>>
JQueryUI实现对话框
查看>>
Java流(Stream)/文件(File)/IO
查看>>
文件处理(压缩与解压)
查看>>
Java中的目录
查看>>
JQuery实现对select选择框的赋值
查看>>
JavaNIO学习(与IO比较)
查看>>
SweetAlert插件
查看>>
Java开发者必读的10篇精选优秀技术文章
查看>>
Java数据库开发
查看>>
编程精华资源(ITeye优秀专栏)大汇总
查看>>
先进软件开发技术与工具
查看>>