C/C++

###### poj 2593Max Sequence【dp】

Max Sequence
 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16666 Accepted: 6980

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

#include<cstring>
#include<cstdio>
#include<cstdlib>
const int M = 1e5+20;
int a[M], b[M], c[M];
int main()
{
int n;
while(scanf("%d", &n)==1, n)
{
int i, j, k;
int r, t;
r = 0;
t = -1001;
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
r += a[i];
if(r > t)
t = r;
if(r < 0)
r = 0;
b[i] = t;
}
r = 0;
t = -1001;
for(i = n-1; i >= 0; i--)
{
r += a[i];
if(r > t)
t = r;
if(r < 0)
r = 0;
c[i] = t;
}
int mx = b[0]+c[1];
for(i = 0; i < n-1; i++)
{
if(mx < b[i]+c[i+1])
mx = b[i]+c[i+1];
}
printf("%d\n", mx);
}
return 0;
} 

#### Max Sequence （DP）

2017-08-16 10:46:40

#### POJ 2479 Maximum sum && 2593 Max Sequence （dp）买一送一

2015-08-26 16:22:28

#### poj 2593 Max Sequence(预处理dp)

2016-06-23 14:35:36

#### 用DP算法的PKU2593Max Sequence的源代码

2009年03月13日 1KB 下载

#### POJ1141 Brackets Sequence （dp动态规划，递归）

2014-05-07 10:40:43

#### POJ 1239-Increasing Sequences（LIS 分割成上升序列-两次DP）

2016-05-21 13:10:25

#### poj2778--DNA Sequence(AC自动机+矩阵优化)

2015-02-03 17:19:01

#### poj 几道简单的dp题

2016-07-19 10:19:34

#### POJ 2442 Sequence

2013-08-16 19:21:29

#### POJ-DP题目列表【开启疯狗模式】

2013-12-04 11:05:48

## 不良信息举报

poj 2593Max Sequence【dp】