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
 
题目大意 :
  每次从最左端起点处走, 最右端是终点, 并且最左端视为无穷小, 最右端视为无穷大,每次走的下一个点必须比上一个点大,问走过后最大子段和是多少。
因为下一次走它会被上一次所影响,很容易想到dp,则状态转移方程为 dp[i] = max( dp[i], dp[j]+pre[i] ) 0 <= j < i , pre[i] > pre[j]。
 
代码示例 :
  

/*
* Author: renyi
* Created Time: 2017/8/31 13:51:36
* File Name:
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
const int maxn = 1e6+5;
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define ll long long ll t_cnt;
void t_st(){t_cnt=clock();}
void t_ot(){printf("you spent : %lldms\n", clock()-t_cnt);}
//开始t_st();
//结束t_ot(); int pre[1050];
int dp[1050]; int main() {
int n ; while (~scanf ("%d", &n) && n){
for (int i = 0; i < n; i++){
scanf ("%d", &pre[i]);
} int ans = 0;
for(int i = 0; i < n; i++){
dp[i] = pre[i];
for(int j = 0; j < i ; j++){
if (pre[i] > pre[j]){
dp[i] = Max(dp[i], dp[j]+pre[i]);
}
}
ans = Max(ans, dp[i]);
}
printf ("%d\n", ans);
} return 0;
}
 

dp-最大递增子段和的更多相关文章

  1. hdu1003 dp(最大子段和)

    题意:给出一列数,求其中的最大子段和以及该子段的开头和结尾位置. 因为刚学过DP没几天,所以还会这题,我开了一个 dp[100002][2],其中 dp[i][0] 记录以 i 为结尾的最大子段的和, ...

  2. hdu1081 DP类最大子段和(二维压缩+前缀和数组/树状数组计数)

    题意:给出一个 n * n 的数字矩阵,问最大子矩阵和是多少. 由于和最长子段和问题类似,一开始想到的就是 DP ,一开始我准备用两个循环进行 DP ,对于每一个 (i,j) ,考察(i - 1,j) ...

  3. Codeforces 1155 D Beautiful Array DP,最大子段和

    题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...

  4. 经典矩阵dp寻找递增最大长度

    竖向寻找矩阵最大递增元素长度,因为要求至少一列为递增数列,那么每行求一下最大值就可以作为len[i]:到i行截止的最长的递增数列长度. C. Alyona and Spreadsheet time l ...

  5. hdu1087 最大递增子段和

    http://acm.split.hdu.edu.cn/showproblem.php?pid=1087 状态方程:sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j, ...

  6. HDU 1003:Max Sum(DP,连续子段和)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  7. HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段

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

  8. dp 46(再做一遍)

    Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多 ...

  9. HDU1087:Super Jumping! Jumping! Jumping!(DP)

    Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...

随机推荐

  1. [转]JavaWeb工程 目录结构

    今天为此事纠结了一段时间. 以下是mavaen推荐的项目目录. ├── pom.xml └── src     ├── main     │   ├── java     │   │   └── my ...

  2. python模块之包

    包:将解决一类问题的模块放在同一目录下就形成了一个包 为了更好的了解包,我们就模拟创建一个包 import os os.makedirs('glance/api') os.makedirs('glan ...

  3. laydate type=time/datetime/date 开始时间和结束时间的输入限制

    最近项目中使用了laydate插件,需要限制开始时间和结束时间的输入 1.type=date 要求:周期开始时间和周期结束时间以天为单位,结束时间不能早于开始时间,可以是同一天. 周期开始时间:< ...

  4. P1094 百钱白鸡

    题目描述 公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱. 输入格式 无. 输出格式 输出所有 ...

  5. java 字节→字符转换流

    OutputStreamWriter:把字节输出流对象转成字符输出流对象 InputStreamReader:把字节输入流对象转成字符输入流对象 FileWriter和FileReader分别是Out ...

  6. JPA查询之Specification以及HQL、SQL查询

    1.Specification //查询条件List List<Predicate> predicateList = new ArrayList<Predicate>(); S ...

  7. linux 自动检测 IRQ 号

    驱动在初始化时最有挑战性的问题中的一个是如何决定设备要使用哪个 IRQ 线. 驱动需 要信息来正确安装处理. 尽管程序员可用请求用户在加载时指定中断号, 这是个坏做法, 因为大部分时间用户不知道这个号 ...

  8. 纯CSS绘制的图形一览

    整理网上一些使用纯CSS绘制的图形示例~~纯属抄袭,哈哈...仅仅是为了自己以后查看! Square(正方形) #square { width: 100px; height: 100px; backg ...

  9. CF1228——记一次和紫名失之交臂的CF

    CF1228--记一次和紫名失之交臂的CF 第无数次和暴涨失之交臂 A 题目大意给定\(l,r\)输出任意一个\(l,r\)之间的每一位都不同的数 \((l <= r <= 10^5)\) ...

  10. ZR7.26

    7.26 A 并查集维护,时间复杂度我写的貌似不大对,先鸽一鸽 B 敦爷:\(w\)是这个区间的最大值当且仅当他是这个区间内最大的 我们发现结合昨天课件内的并查集 发现我们每次不断合并的本质是把所有\ ...