【noiOJ】p1481
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=s2Your 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的更多相关文章
- 【noiOJ】P1996
1996:登山 查看 提交 统计 提问 总时间限制: 5000ms 内存限制: 131072kB 描述 五一到了,PKU-ACM队组织大家去登山观光,队员们发现山上一个有N个景点,并且决定按照顺序 ...
- 【noiOJ】p1759
1759:最长上升子序列 查看 提交 统计 提问 总时间限制: 2000ms 内存限制: 65536kB 描述 一个数的序列bi,当b1 < b2 < ... < bS的时候,我 ...
- 【noiOJ】p6253
t6253:用二分法求方程的根 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 用二分法求下面方程在(-10, 10)之间的一个根. 2x3- 4x2+ 3x ...
- 【noiOJ】p1794
t1794:集合加法 查看 提交 统计 提问 总时间限制: 3000ms 内存限制: 65536kB 描述 给出2个正整数集合A = {pi | 1 <= i <= a},B = {q ...
- 【noiOJ】p1776
t1776:木材加工 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 木材厂有一些原木,现在想把这些木头切割成一些长度相同的小段木头,需要得到的小段的数目是给 ...
- 【noiOJ】p8210
10:河中跳房子 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一个岩石跳到另一个岩石.这项激动人心 ...
- 【noiOJ】p7939
09:膨胀的木棍 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 当长度为L的一根细木棍的温度升高n度,它会膨胀到新的长度L'=(1+n*C)*L,其中C是热 ...
- 【noiOJ】p7914(..)
08:不重复地输出数 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 输入n个数,从小到大将它们输出,重复的数只输出一次.保证不同的数不超过500个. 输入 ...
- 【noiOj】p8207(233)
07:和为给定数 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 给出若干个整数,询问其中是否有一对数的和等于给定的数. 输入 共三行:第一行是整数n(0 & ...
随机推荐
- Object.create 函数 (JavaScript)
创建一个具有指定原型且可选择性地包含指定属性的对象. 语法 Object.create(prototype, descriptors) 参数 prototype 必需. 要用作原型的对象. 可以为 ...
- Debian 的 preinst, postinst, prerm, 和 postrm 脚本
转自:http://jianjian.blog.51cto.com/35031/395468 这些是软件包安装前后自动运行的可执行脚本. 统称为控制文件, 是 Deian 软件包的"控制&q ...
- 中断处理流程,ok6410
中断处理流程 CPU在工作的过程中,经常需要与外设进行交互,交互的方式包括”轮询方式”,”中断方式”. 1.轮询方式: CPU不断地查询设备的状态.该方式实现比较简单,但CPU利用率很低,不适合多任务 ...
- 注解:【无连接表的】Hibernate单向N->1关联
Person与Address关联:单向N->1,[无连接表的] Person.java package org.crazyit.app.domain; import javax.persiste ...
- loj 1099(最短路)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25956 思路:dist[v][0]代表走到点v的最短路,dist[ ...
- 网页或php服务连不上的几个可能原因
1.webserver未启动. 2.php未启动. 3.url中端口和webserver配置文件中的不一致.
- Arduino101学习笔记(二)—— 一些注意的语法点
1.宏定义 2.整数常量 3.支持C++ String类 (1)String 方法 charAt() compareTo() concat() endsWith() equals() equalsIg ...
- Hbase原理、基本概念、基本架构
来源:http://blog.csdn.net/woshiwanxin102213/article/details/17584043 概述 HBase是一个构建在HDFS上的分布式列存储系统:HBas ...
- phpstudy配置ssl
https://yunpan.cn/cPEyzVycbkiE3 (提取码:03aa) 1.重写规则:http://www.cnphp.info/htaccess-rewrite.html 2.相关文档 ...
- sudo -u hdfs hdfs balancer出现异常 No lease on /system/balancer.id
16/06/02 20:34:05 INFO balancer.Balancer: namenodes = [hdfs://dlhtHadoop101:8022, hdfs://dlhtHadoop1 ...