Max Sequence
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 17678   Accepted: 7401

Description

Give you N integers a1, a2 ... aN (|ai| <=1000, 1 <= i <= N). 




You should output S. 

Input

The input will consist of several test cases. For each test case, one integer N (2 <= N <= 100000) is given in the first line. Second line contains N integers. The input is terminated by a single line with N = 0.

Output

For each test of the input, print a line containing S.

Sample Input

5
-5 9 -5 11 20
0

Sample Output

40

Source

POJ Monthly--2005.08.28,Li Haoyuan

题解:这个题2479差不多,具体可以看2479的题解,不过感觉这道题的测试数据要比2479弱一些,轻松AC

//主要是刷几道dp练练手

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = 1e6+7, inf = -1e9+7;
int a[maxn], ls[maxn], rs[maxn], rst[maxn], s; int main()
{
int n;
while (~scanf("%d", &n) && n)
{
for (int i=0; i<n; i++)
scanf("%d", &a[i]);
ls[0] = a[0], rs[n-1] = rst[n-1] = a[n-1], s = inf;
for (int i=1; i<n; i++)
ls[i] = max(ls[i-1]+a[i], a[i]);
for (int i=n-2; i>=0; i--)
rs[i] = max(rs[i+1]+a[i], a[i]),
rst[i] = max(rst[i+1], rs[i]);
for (int i=1; i<n; i++)
s = max(s, ls[i-1]+rst[i]);
printf("%d\n", s);
}
return 0;
}

POJ 2593 Max Sequence的更多相关文章

  1. 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} 即求两个子序列和的和的最大 ...

  2. poj 2593 Max Sequence(线性dp)

    题目链接:http://poj.org/problem?id=2593 思路分析:该问题为求给定由N个整数组成的序列,要求确定序列A的2个不相交子段,使这m个子段的最大连续子段和的和最大. 该问题与p ...

  3. POJ 2593&&2479:Max Sequence

    Max Sequence Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16329   Accepted: 6848 Des ...

  4. poj 1699 Best Sequence(AC自己主动机+如压力DP)

    id=1699" target="_blank" style="">题目链接:poj 1699 Best Sequence 题目大意:给定N个D ...

  5. (线性dp,最大连续和)Max Sequence

    Max Sequence Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18511   Accepted: 7743 Des ...

  6. [poj P1141] Brackets Sequence

    [poj P1141] Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K   Special Judge Description ...

  7. poj 2593&&poj2479(最大两子段和)

    Max Sequence Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16850   Accepted: 7054 Des ...

  8. Poj 1019 Number Sequence( 数据分析和操作)

    一.题目大意 有这样一个序列包含S1,S2,S3...SK,每一个Si包括整数1到 i.求在这个序列中给定的整数n为下标的数. 例如,前80位为1121231234123451234561234567 ...

  9. poj2593 Max Sequence(两个不相交字段的最大总和与)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=2593">http://poj.org/prob ...

随机推荐

  1. JSON总结-持续更新补充

    基本的json格式 { "name": "jobs", "boolean": true, "age": null, &q ...

  2. MyEclipse常用操作

    选择你要注释的那一行或多行代码,按Ctrl+/即可,取消注释也是选中之后按Ctrl+/即可. 如果你想使用的快捷键的注释是的话,那么你的快捷键是ctrl+shift+/我以前都是手动注释的,直接打// ...

  3. Spring Boot 集成swagger实例

    原文:https://github.com/x113773/testall/issues/5 1. 首先添加maven依赖``` <dependency> <groupId>i ...

  4. 【LeetCode】87. Scramble String

    题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...

  5. MacTex XeLaTex xdvipdfmx:fatal: pdf_ref_obj(): passed invalid object. 报错的解决方法

    在使用MacTex配合TexStudio编译beamer的时候,爆出如下错误, xdvipdfmx:fatal: pdf_ref_obj(): passed invalid object. 结果尝试其 ...

  6. 原声js 五子棋 源码

    Welcome to use MarkDown <style type="text/css"> .box{ width: 600px; height: 600px; b ...

  7. [基础架构]PeopleSoft Application Server 重要文件说明

    我们都知道PeopleSoft是由几个不同的服务组成的,他们在PeopleSoft体系结构中扮演着自己的角色.这些服务具有不同的文件结构并包含重要的可执行文件和配置文件. 以下是Peoplesoft体 ...

  8. Java数据类型在实际开发中的应用二枚举类型

    在实际编程中,往往存在着这样的"数据集",它们的数值在程序中是稳定的,而且"数据集"中的元素是有限的.在JDK1.5之前,人们用接口来描述这一种数据类型. 1. ...

  9. python机器学习模块安装

    环境:RHEL6.5 离线安装 ############################################################################ 一,本地yum ...

  10. Java 日志框架终极教程

    概述 对于现代的 Java 应用程序来说,只要被部署到真实的生产环境,其日志的重要性就是不言而喻的,很难想象没有任何日志记录功能的应用程序被运行于生产环境中.日志 API 所能提供的功能是多种多样的, ...