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 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 a integer m (M > 0), your task is to find m pairs of I and J which make sum (i1J1) + SUM (i2J2) + SUM (i3J3) + ... + sum (imJm) Maximal (ix≤iy≤jxOr Ix≤jy≤jxis 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 (ixJx) (1≤x≤m) instead. ^_^
Inputeach test case would begin with a integers m and n, followed by n integers S1, S2, S3... SN.
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 Output68HintHuge 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