注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

[hdu]1024 Max Sum Plus Plus  

2012-08-21 00:30:52|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
状态转移方程: dp[i][j]=max{dp[i][j-1]+A[j],dp[i-1][t]+a[j] (i-1<=t<n-m+i) }
题目放出:

Max Sum Plus Plus

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


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 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. ^_^
 

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
Hint
Huge input, scanf and dynamic programming is recommended.
 

Author
JGShining(极光炫影)
 

代码:



#include<iostream>
#include<cmath>
#include<string.h>
using namespace std;

int
num[1000100],f[1000100],k[1000100];
int
main()
{

int
m,n;
int
_max;
while
(cin>>m>>n)
{

for
(int i = 1;i <= n;i ++) scanf("%d",&num[i]);
memset(f,0,sizeof(f));
memset(k,0,sizeof(k));
for
(int i = 1;i <= m;i ++)
{

_max = -9999999;
for
(int j = i;j <= n;j ++)
{

f[j] = max(f[j - 1],k[j - 1]) + num[j];
k[j - 1] = _max;
if
(_max < f[j]) _max = f[j];
}
}

cout<<_max<<endl;
}
}

/*
f[n] = max(f[n-1],k[n-1])+num[i];
(1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767).
Sample Input
1 3 1 2 3
2 6 -1 4 -2 3 -2 3


Sample Output
6
8*/




  评论这张
 
阅读(149)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018