Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1024
Max Sum plus Plus
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 21926 Accepted Submission (s): 7342
Problem Descriptionnow I Think you have got a AC in IGNATIUS.L ' s "Max Sum" problem. To is a brave acmer, we always challenge ourselves to more difficult problems. Now you is faced with a more difficult problem.
Given a consecutive number sequence S
1, S
2, S
3, S
4... S
x, ... S
N(1≤x≤n≤1,000,000, -32768≤s
x≤32767). We define a function sum (i, j) = S
I+ ... + S
J(1≤i≤j≤n).
Now given a integer m (M > 0), your task is to find m pairs of I and J which make sum (i
1J
1) + SUM (i
2J
2) + SUM (i
3J
3) + ... + sum (i
mJ
m) Maximal (i
x≤i
y≤j
xOr I
x≤j
y≤j
xis not allowed).
But I ' m lazy, I don't want to the write a Special-judge module, so you don ' t has to output m pairs of I and j, just output th e maximal summation of sum (i
xJ
x) (1≤x≤m) instead. ^_^
Inputeach test case would begin with a integers m and n, followed by n integers S
1, S
2, S
3... S
N.
Process to the end of file.
Outputoutput the maximal summation described above in one line.
Sample INPUT1 3 1 2 32 6-1 4-2 3-2 3
Sample Output68
HintHuge input, scanf and dynamic programming is recommended.
Authorjgshining (Aurora Dazzle) test instructions: Enter the M,n and enter the number of N. The maximum continuous m segment and.
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespacestd;Const intOO =0x7fffffff;inta[1000005];intdp[1000005];intmax[1000005];intMain () {intM,n; while(~SCANF ("%d%d", &m, &N)) { for(intI=1; i<=n; i++) {scanf ("%d", &A[i]); Max[i]=0; Dp[i]=0; } intM; dp[0] =0; max[0] =0; for(intI=1; i<=m; i++) {M= -Oo; for(intJ=i; j<=n; J + +) {Dp[j]= Max (dp[j-1]+A[J], max[j-1]+A[j]); Max[j-1] =M; M=Max (Dp[j], M); }} printf ("%d\n", M); } return 0;}
HDU Max Sum plus Plus