﻿﻿

Max Sum Plus Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21561    Accepted Submission(s): 7227

Problem Description
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.

Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767). We define a function sum(i, j) = Si + ... + Sj (1 ≤ i ≤ j ≤ n).

Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im, jm) maximal (ix ≤ iy ≤ jx or ix ≤ jy ≤ jx is not allowed).

But Im lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(ix, jx)(1 ≤ x ≤ m) instead. ^_^

Input
Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
Process to the end of file.

Output
Output the maximal summation described above in one line.

Sample Input
1 3 1 2 3 2 6 -1 4 -2 3 -2 3

Sample Output
6 8

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<stack>
#define mem(x,y) memset(x,y,sizeof(x))
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define inf 0x80000000
using namespace std;
const int N=1e6+10;
int pp[N],dp[N],bb[N];
int main()
{
int n,m,i,j,k,mmax;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i<=m;i++)
scanf("%d",&pp[i]);
for(i=0;i<=m;i++)
dp[i]=0,bb[i]=0;
for(i=1;i<=n;i++)
{
mmax=inf;
for(j=i;j<=m;j++)
{
if(dp[j-1]>bb[j-1])
dp[j]=dp[j-1]+pp[j];
else dp[j]=bb[j-1]+pp[j];
bb[j-1]=mmax;
if(mmax<dp[j])
mmax=dp[j];
}
bb[j-1]=mmax;
//printf("%d\n",bb[j-1]);
}
printf("%d\n",mmax);
}
return 0;
}
`

HDU1024 Max Sum Plus Plus(DP动态规划 最大子串和增强版)

2015-08-23 21:12:43

hdu 1024 Max Sum Plus Plus（动态规划+m子段和的最大值）

2016-01-28 12:40:56

HDU - 1024 Max Sum Plus Plus（dp）

2017-12-26 12:26:23

hdu Max Sum Plus Plus(最大m段子段和)

2013-03-07 12:09:36

杭电OJ——1024 Max Sum Plus Plus（另类的动态规划！）

2012-10-13 15:13:51

hdu1024HDU 1024 Max Sum Plus Plus（动态规划 很详很详解）

2015-01-20 10:14:11

HDU - 1024 Max Sum Plus Plus（DP + 滚动数组）

2015-09-26 09:59:23

HDU 1024 Max Sum Plus Plus Dp题解

2014-08-15 13:38:23

最大m子段和问题 Max Sum Plus Plus —— 动态规划

2014-05-31 23:31:23

Hdoj 1024 Max Sum Plus Plus 【DP】

2015-04-09 22:38:51

不良信息举报

hdoj 1024 Max Sum Plus Plus 【简单dp】