m的范围没给,很坑爹
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12747 Accepted Submission(s): 4202
Problem DescriptionNow 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 I`m 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. ^_^ InputEach test case will begin with two 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 3
2 6 -1 4 -2 3 -2 3 Sample Output6
8
Hint
Huge input, scanf and dynamic programming is recommended.
AuthorJGShining(极光炫影)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff
typedef __int64 LL;
#define N 1000100LL dp[N][];
LL g[N];int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
int m,n;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(int i=;i<=n;i++)
{
g[i]=-;
dp[i][]=dp[i][]=-;
}
int a=,b=;
for(int i=;i<=n;i++)
{
swap(a,b);
int tmp;
scanf("%d",&tmp);
for(int j=m;j>=;j--)
{
if(j>i) continue;
dp[j][a]=max(dp[j][b],g[j-])+tmp;
if(dp[j][a] > g[j]) g[j] = dp[j][a];
}
}
printf("%I64d\n",g[m]);
}
return ;
}