1481:Maximum sum

总时间限制: 
1000ms

内存限制: 
65536kB
描述
Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:

                     t1     t2 
d(A) = max{ ∑ai + ∑aj | 1 <= s1 <= t1 < s2 <= t2 <= n }
i=s1 j=s2

Your task is to calculate d(A).

输入
The input consists of T(<=30) test cases. The number of test cases (T) is given in the first line of the 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.
输出
Print exactly one line for each test case. The line should contain the integer d(A).
样例输入
1

10
1 -1 2 2 3 -3 4 -4 5 -5
样例输出
13
提示
In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer.

Huge input,scanf is recommended.

来源
POJ Contest,Author:Mathematica@ZSU
source:最大双子序列和,枚举i,分别统计i左边最大子序列和右边最大子序列。(改变一下代码风格)
 #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int n,datanum,maxn;
int a[+],leftmax[+],rightmax[+];
int main()
{
int w,i;
scanf("%d",&datanum);
for (w=;w<=datanum;w++)
{
memset(a,,sizeof());
memset(leftmax,,sizeof(leftmax));
memset(rightmax,,sizeof(rightmax));
scanf("%d",&n);
for (i=;i<=n;i++)
scanf("%d",&a[i]);
leftmax[]=a[];
for (i=;i<=n;i++)
if (leftmax[i-]>) leftmax[i]=leftmax[i-]+a[i];
else leftmax[i]=a[i];
for (i=;i<=n;i++)
if (leftmax[i]<leftmax[i-]) leftmax[i]=leftmax[i-];
rightmax[n]=a[n];
for (i=n-;i>=;i--)
if (rightmax[i+]>) rightmax[i]=rightmax[i+]+a[i];
else rightmax[i]=a[i];
for (i=n-;i>=;i--)
if (rightmax[i]<rightmax[i+])
rightmax[i]=rightmax[i+];
maxn=-;
for (i=;i<n;i++)
maxn=max(maxn,leftmax[i]+rightmax[i+]);
printf("%d\n",maxn);
}
return ;
}

【noiOJ】p1481的更多相关文章

  1. 【noiOJ】P1996

    1996:登山 查看 提交 统计 提问 总时间限制:  5000ms 内存限制:  131072kB 描述 五一到了,PKU-ACM队组织大家去登山观光,队员们发现山上一个有N个景点,并且决定按照顺序 ...

  2. 【noiOJ】p1759

    1759:最长上升子序列 查看 提交 统计 提问 总时间限制:  2000ms 内存限制:  65536kB 描述 一个数的序列bi,当b1 < b2 < ... < bS的时候,我 ...

  3. 【noiOJ】p6253

    t6253:用二分法求方程的根 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 用二分法求下面方程在(-10, 10)之间的一个根. 2x3- 4x2+ 3x ...

  4. 【noiOJ】p1794

    t1794:集合加法 查看 提交 统计 提问 总时间限制:  3000ms 内存限制:  65536kB 描述 给出2个正整数集合A = {pi | 1 <= i <= a},B = {q ...

  5. 【noiOJ】p1776

    t1776:木材加工 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 木材厂有一些原木,现在想把这些木头切割成一些长度相同的小段木头,需要得到的小段的数目是给 ...

  6. 【noiOJ】p8210

    10:河中跳房子 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一个岩石跳到另一个岩石.这项激动人心 ...

  7. 【noiOJ】p7939

    09:膨胀的木棍 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 当长度为L的一根细木棍的温度升高n度,它会膨胀到新的长度L'=(1+n*C)*L,其中C是热 ...

  8. 【noiOJ】p7914(..)

    08:不重复地输出数 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 输入n个数,从小到大将它们输出,重复的数只输出一次.保证不同的数不超过500个. 输入 ...

  9. 【noiOj】p8207(233)

    07:和为给定数 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 给出若干个整数,询问其中是否有一对数的和等于给定的数. 输入 共三行:第一行是整数n(0 & ...

随机推荐

  1. Web框架本质

    Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:utf- ...

  2. Sexagenary Cycle(天干地支法表示农历年份)

    Sexagenary Cycle Time Limit: 2 Seconds      Memory Limit: 65536 KB 题目链接:zoj 4669 The Chinese sexagen ...

  3. JavaScript - 变量,作用域,内存

    JavaScript 变量可以用来保存两种类型的值:基本类型值和应用类型值.基本类型的值源自以下5种基本数据类型:Undefined.Null.Bollean.Number和String. 所有变量都 ...

  4. Java Server returned HTTP response code: 401

    今天写一个小功能需要通过http请求获取一些返回数据,但是在登陆时是需要进行用户名和密码的校验的.写好之后请求,返回异常Java Server returned HTTP response code: ...

  5. Lucene.net 全文检索 盘古分词

    lucene.net + 盘古分词 引用: 1.Lucene.Net.dll 2.PanGu.Lucene.Analyzer.dll 3.PanGu.HighLight.dll 4.PanGu.dll ...

  6. 在Salesforce中调用外部系统所提供的的Web Service

    这里需要提供外部service所对应的WSDL文件(Salesforce只支持从本地上传),并且提供的WSDL文件有如下两点要求: 1):wsdl 文件只能有一个binding,Salesforce是 ...

  7. HDU 3586 Information Disturbing 树形DP+二分

    Information Disturbing Problem Description   In the battlefield , an effective way to defeat enemies ...

  8. C#分布式缓存Couchbase使用

    目前C#业界使用得最多的 Cache 系统主要是 Memcached和 Redis. 这两个 Cache 系统可以说是比较成熟的解决方案,也是很多系统当然的选择. 一.简介 目前C#业界使用得最多的 ...

  9. RecyclerView再封装

    RecyclerView做为ListView的替代品,已经出了很久了,既然是替代品,那自然有些ListView没有的优点.比如说:可以随意切换list,grid,stagger.可以指定一个或多个it ...

  10. EntityFramework Code First 手写代码实现生成数据库

    第一步:写实体类 第二步:写一个实体操作类,此类必须继承Dbcontext,此处的属性,将会在初始化时(第一次作,增,删,改的时候),生成相应的表. 第三步:运行程序,会自动建表 注意: 若实体类发生 ...