(线性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问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...
随机推荐
- jQuery插件开发的基本形式
(function ($, window, document, undefined) { "use strict"; var defaults = { pageIndex: 0, ...
- PCIE\AURORA\SRIO协议对比
http://www.eefocus.com/communication/335836/p3
- const函数
1. const修饰成员函数:表示不可以修改成员变量 class test{ public: test(){ i_ = ; } int Get() const{ //i_ = 0; //error:不 ...
- Fourier Transform Complex Conjugate Discussion
FT of function $f(t)$ is to take integration of the product of $f(t)$ and $e^{-j\Omega t}$. By separ ...
- sql server对已创建的表增加属性(自动增序)
新建此表时把ID设为INT类型,然后设Identity为yes,种子为1递增就可以了.如果这张表已经建了,你在最后加一个字段叫ID,然后和上面一样操作,然后保存即可自增.(一定要设置完在保存) alt ...
- 实验九 在JSP中使用数据库
实验性质:验证性 实验学时: 1学时 实验地点: 一 .实验目的与要求 1. 掌握在JSP中使用数据库的方法. 2. 掌握JSP对数据库的基本操作:增.删.改.查. 二. 实验内容 1.JSP访问数据 ...
- codeforces 1065F Up and Down the Tree
题目链接:codeforces 1065F Up and Down the Tree 题意:给出一棵树的节点数\(n\)以及一次移动的最大距离\(k\),现在有一个标记在根节点1处,每一次可以进行一下 ...
- Nagios 监控 Httpd 并发数插件
工作需要监控Httpd并发数,找不到合适的插件,花时间研究了一下Nagios监控内存的脚本,做了一些修改,完成了脚本.监控内存脚本:http://www.cnblogs.com/Mrhuangrui/ ...
- Angular、React.js 和Node.js到底选谁?
为了工作,程序员选择正确的框架和库来构建应用程序是至关重要的,这也就是为什么Angular和React之间有着太多的争议.Node.js的出现,让这场战争变得更加复杂,虽然有选择权通常是一件很棒的事情 ...
- 【HDU3595】GG and MM(博弈论)
[HDU3595]GG and MM(博弈论) 题面 HDU 一个游戏由多个游戏组成,每次每个操作者必须操作所有可以操作的游戏,操作集合为空者输. 每个游戏由两堆石子组成,每次可以从较多的那一堆中取走 ...