(线性dp 最大连续和)POJ 2479 Maximum sum
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 44459 | Accepted: 13794 | 
Description
Your task is to calculate d(A).
Input
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.
Output
Sample Input
1 10
1 -1 2 2 3 -3 4 -4 5 -5
Sample Output
13 和poj2593几乎一样。
https://www.cnblogs.com/Weixu-Liu/p/10512447.html
C++代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = ;
int a[maxn],dpl[maxn],dpr[maxn],m1[maxn],m2[maxn];
int Inf = -0x3f3f3f3f;
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i = ; i <= n; i++){
scanf("%d",&a[i]);
}
memset(dpl,,sizeof(dpl));
memset(dpr,,sizeof(dpr));
m1[] = m2[n+] = Inf;
for(int i = ; i <= n; i++){
dpl[i] = max(dpl[i-] + a[i],a[i]);
if(m1[i-] < dpl[i])
m1[i] = dpl[i];
else
m1[i] = m1[i-];
}
for(int i = n; i >= ; i--){
dpr[i] = max(dpr[i+] + a[i],a[i]);
if(m2[i+] < dpr[i])
m2[i] = dpr[i];
else
m2[i] = m2[i+];
}
int maxsum = Inf;
int tmp[maxn];
for(int i = ; i <= n-; i++){
tmp[i] = m1[i] + m2[i+];
if(maxsum < tmp[i])
maxsum = tmp[i];
}
printf("%d\n",maxsum);
}
return ;
}
(线性dp 最大连续和)POJ 2479 Maximum sum的更多相关文章
- POJ 2479 Maximum sum(双向DP)
		
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36100 Accepted: 11213 Des ...
 - POJ 2479 Maximum sum 解题报告
		
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40596 Accepted: 12663 Des ...
 - poj 2479 Maximum sum (最大字段和的变形)
		
题目链接:http://poj.org/problem?id=2479 #include<cstdio> #include<cstring> #include<iostr ...
 - [poj 2479] Maximum sum         --     转载
		
转自 CSND 想看更多的解题报告: http://blog.csdn.net/wangjian8006/article/details/7870410 ...
 - POJ #2479 - Maximum sum
		
Hi, I'm back. This is a realy classic DP problem to code. 1. You have to be crystal clear about what ...
 - poj 2479 Maximum sum(递推)
		
 题意:给定n个数,求两段连续不重叠子段的最大和. 思路非常easy.把原串划为两段.求两段的连续最大子串和之和,这里要先预处理一下,用lmax数组表示1到i的最大连续子串和,用rmax数组表示n ...
 - POJ 2479 Maximum sum  POJ 2593 Max Sequence
		
d(A) = max{sum(a[s1]..a[t1]) + sum(a[s2]..a[t2]) | 1<=s1<=t1<s2<=t2<=n} 即求两个子序列和的和的最大 ...
 - (线性dp,LCS) POJ 1458 Common Subsequence
		
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65333 Accepted: 27 ...
 - poj 1050 To the Max(线性dp)
		
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...
 
随机推荐
- ES 6 系列 - Module 的语法
			
es 6 大幅度优化了模块化编程的规范. 写在前面:在 es6 之前,说起 js 的模块化,一般都避不开 CommonJs 和 AMD 两种方案.这两种方案,前者应用于服务器,后者应用于浏览器.而 e ...
 - 进程创建fork()
			
简单进程创建例子: #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> #include ...
 - H5 history.pushState 在微信内修改url后点击用safari打开/复制链接是修改之前的页面
			
解决方案:url参数增加随机参数 function wxRefresh() { var replaceQueryParam = (param, newval, search) => { var ...
 - Spring 使用介绍(九)—— 零配置(二)
			
三.Bean定义 1.开启bean定义注解支持 开启注解支持须添加以下配置项: <context:component-scan base-package="cn.matt"/ ...
 - VM下安装Kali虚拟机
			
VM下Kali虚拟机安装 下载kali Linux系统镜像 下载地址:http://mirrors.hust.edu.cn/kali-images/ 网页如下: kali官网:http://www.k ...
 - Gym100496H-House of Representatives-树
			
树上每个元素有一个p,元素之间有距离d,计算一个元素u,使得sigma(d(i,u)*pi)最小. 两次dfs,第一次计算本节点以下的sigma(),第二次利用sump求解出ans. #include ...
 - 「NOI2003」逃学的小孩
			
传送门:>HERE< 题意:给出一棵树(带权),要从一个节点C先走到距离它近的一个节点B,再走到A,要求最坏情况下的总路程(即最长). 解题思路: 乍一看,A,B,C都没给出,这怎么求? ...
 - yoj维护
			
维护 启动容器 docker start yoj 暂停容器 docker stop yoj 重启容器 docker restart yoj 进入容器的终端 docker attach yok 保存容器 ...
 - RSS阅读器“阅读原文”报错400
			
问题 使用SpringMVC框架,实现了RSS订阅,在FoxMail的RSS订阅页面,点击[阅读原文],报错400 . 每个RSS文章的链接是:https://jiashubing.cn/forum/ ...
 - Nagios 使用 NSClient++ 监控Windows Server
			
在被监控的Windows server 主机上安装NSClinet++下载地址:https://www.nsclient.org/download/32bit:http://files.nsclien ...