poj----Maximum sum(poj 2479)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 30704 | Accepted: 9408 |
Description
Your task is to calculate d(A).
Input
Output
Sample Input
1 10
1 -1 2 2 3 -3 4 -4 5 -5
Sample Output
13
Hint
Huge input,scanf is recommended.
Source
#include<iostream>
#include<cstdio>
#define maxn 50001
#include<algorithm>
using namespace std;
int a[maxn];
int left[maxn];
int right[maxn];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int t,i;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d",&a[i]);
//此时::left【i】为包涵i最大字段和
::left[]=a[];
for( i=; i<n;i++)
if(::left[i-]<)
::left[i]=a[i];
else
::left[i]=::left[i-]+a[i];
//此时left[i]为i左边最大字段和
for(i=; i<n;i++)
::left[i]=max(::left[i],::left[i-]);
::right[n-]=a[n-];
for(i=n-;i>=;i--)
{
if(::right[i+]<)
::right[i]=a[i];
else
::right[i]=::right[i+]+a[i];
}
for(i=n-;i>=;i--)
::right[i]=max(::right[i+],::right[i]);
int res=-;
for(i=;i<n;i++)
{
res=max(res,::left[i-]+::right[i]);
}
printf("%d\n",res);
}
return ;
}
poj----Maximum sum(poj 2479)的更多相关文章
- 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} 即求两个子序列和的和的最大 ...
- 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 ...
- (线性dp 最大连续和)POJ 2479 Maximum sum
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 44459 Accepted: 13794 Des ...
- POJ 2479 Maximum sum(双向DP)
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36100 Accepted: 11213 Des ...
- ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法
POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS Memory Limit:65536KB 64bit IO Fo ...
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- POJ 2479-Maximum sum(线性dp)
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33918 Accepted: 10504 Des ...
随机推荐
- Ubuntu 常用命令大全
Ubuntu 常用命令大全查看软件 xxx 安装内容#dpkg -L xxx查找软件#apt-cache search 正则表达式查找文件属于哪个包#dpkg -S filename apt-file ...
- [3] 球(Sphere)图形的生成算法
顶点数据的生成 bool YfBuildSphereVertices ( Yreal radius, Yuint slices, Yuint stacks, YeOriginPose originPo ...
- Candy leetcode java
题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...
- Unable to find manifest signing certificate in the certificate store
方法一:把DEF项目的属性->Signing选项->Sign the ClickOnce manifests 勾去掉,这样就可以编绎通过了: 方法二:用记事本打开 *.csproj文件 , ...
- Bootstrap学习js插件篇之下拉菜单
案例 通过此插件可以为几乎所有东西添加下拉菜单,包括导航条.标签页.胶囊式按钮. 用于导航条 导航条分为四个部分.第一部分导航头,第二部分导航列,第三部分form查询表单,第四部分导航列. <n ...
- 深入理解this和call、bind、apply对this的影响及用法
首先看一道网易的面试题: var a = { a:"haha", getA:function(){ console.log(this.a); } } var b = { a:&qu ...
- PL/SQL 下 Command window 与 SQL window 的区别
1.Command window实现了SQL*Plus的所有功能,允许运行sql*plus命令,sql命令,sql脚本. 2.SQL window用于执行sql语句,显示sql输出,执行统计信息.(测 ...
- Tomcat gzip果然强大,js文件压缩率50%以上
Tomcat配置使用gzip,在server.xml中 <Connector port="9098" protocol="HTTP/1.1" connec ...
- Inner Classes with TypeScript
原文:https://blog.oio.de/2014/03/21/inner-classes-typescript/ b.ts class Foo { sex:string; say(){ new ...
- SqlServer2008安装时系统配置检查器重新启动计算机失败
系统:win7 64 旗舰版 软件版本:sqlserver 2008 在安装前执行:系统配置检查器 的时候报错 ‘重新启动计算机失败’,如下图 处理办法: RebootRequiredCheck ...