dp-最大递增子段和
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.
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.
/*
* 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-最大递增子段和的更多相关文章
- hdu1003 dp(最大子段和)
题意:给出一列数,求其中的最大子段和以及该子段的开头和结尾位置. 因为刚学过DP没几天,所以还会这题,我开了一个 dp[100002][2],其中 dp[i][0] 记录以 i 为结尾的最大子段的和, ...
- hdu1081 DP类最大子段和(二维压缩+前缀和数组/树状数组计数)
题意:给出一个 n * n 的数字矩阵,问最大子矩阵和是多少. 由于和最长子段和问题类似,一开始想到的就是 DP ,一开始我准备用两个循环进行 DP ,对于每一个 (i,j) ,考察(i - 1,j) ...
- Codeforces 1155 D Beautiful Array DP,最大子段和
题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...
- 经典矩阵dp寻找递增最大长度
竖向寻找矩阵最大递增元素长度,因为要求至少一列为递增数列,那么每行求一下最大值就可以作为len[i]:到i行截止的最长的递增数列长度. C. Alyona and Spreadsheet time l ...
- hdu1087 最大递增子段和
http://acm.split.hdu.edu.cn/showproblem.php?pid=1087 状态方程:sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j, ...
- HDU 1003:Max Sum(DP,连续子段和)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- dp 46(再做一遍)
Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多 ...
- HDU1087:Super Jumping! Jumping! Jumping!(DP)
Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...
随机推荐
- Vue 列表动画实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mybatis查询无结果, 数据库运行相同sql查询出结果
一.问题描述 mybatis查询无结果, 数据库运行相同sql查询出结果, 如下 这是数据库记录 这是mybatis查询出的结果, 记录条数0 这是直接将控制台一模一样的sql查询语句放到Navica ...
- Python--day61--安装Django,Django项目的启动和设置运行端口和关闭运行端口
0,安装Django 1,Django项目的启动 2,设置运行端口和关闭运行端口
- UVA 11732——Trie
解题思路: 首先我们可以发现: 1.若两个字符串A.B不相等,且它们的公共前缀为S,则它们的比较次数为:2 * len(S) + 1: 2.若两个字符串相等,设为A,则它们的比较次数为 2 * ( l ...
- js 替换指定位置的字符串
不多bb,直接代码 //str:原始字符串,index,开始位置,changeStr,改变后的字 changeStr(str,index,changeStr){ return str.substr(0 ...
- P1025 最大完美度
题目描述 定义一个字符串的完美度为字符串中所有字符的完美度的和. 现在给你一个只含字母的字符串s, 每一个字母的完美度由你进行分配, 可以分配给一个字母[1,26]中的一个数字作为完美度, 但每个字母 ...
- H3C 示例:计算子网地址
- Linux 旗标实现
Linux 内核提供了一个遵守上面语义的旗标实现, 尽管术语有些不同. 为使用旗标, 内核 代码必须包含 <asm/semaphore.h>. 相关的类型是 struct semaphor ...
- Vue中的scoped及穿透方法(修改第三方组件局部的样式)
何为scoped? 在vue文件中的style标签上,有一个特殊的属性:scoped.当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组 ...
- vue-learning:37 - router - 目录
vue路由vue-router 目录 前端路由历史 服务端渲染(SSR:server side render) 客户端路由(client side routing) 前端路由实现原理 hash模式: ...