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
 
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream> using namespace std;
#define N 1000010
#define INF 0xfffffff
int dp[N];
int M[N];
int Max;
int a[N]; int main()
{
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
dp[i]=;
M[i]=;
}
dp[]=;
M[]=;
for(int i=;i<=m;i++)
{
Max=-INF;
for(int j=i;j<=n;j++)
{
dp[j]=max(dp[j-]+a[j],M[j-]+a[j]);
M[j-]=Max;
Max=max(Max,dp[j]);
}
}
printf("%d\n",Max);
}
return ;
}

Max Sum Plus Plus-HDU1024(dp)的更多相关文章

  1. 【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]

    [题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plu ...

  2. HDU1024 Max Sum Plus Plus 【DP】

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. hdu1024 Max Sum Plus Plus 滚动dp

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU 1024:Max Sum Plus Plus(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Problem Description Now I think you ...

  5. HDU 1024 Max Sum Plus Plus【DP】

    Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we ...

  6. HDU 1024 Max Sum Plus Plus(DP的简单优化)

    Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...

  7. Max Sum—hdu1003(简单DP) 标签: dp 2016-05-05 20:51 92人阅读 评论(0)

    Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  8. HDU 1024:Max Sum Plus Plus(DP,最大m子段和)

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU1024 Max Sum Plus Plus(dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 #include<iostream> #include<vector> #i ...

  10. HDU 1024 Max Sum Plus Plus 简单DP

    这题的意思就是取m个连续的区间,使它们的和最大,下面就是建立状态转移方程 dp[i][j]表示已经有 i 个区间,最后一个区间的末尾是a[j] 那么dp[i][j]=max(dp[i][j-1]+a[ ...

随机推荐

  1. 自制Jquery下拉框插件

    (function ($) { $.fn.select3 = function (option) { $(this).each(function () { var _this = $(this); v ...

  2. 3.12 在运算和比较时使用NULL值

    问题:NULL值永远不会等于或不等于任何值,也包括NULL值自己,但是需要像计算真实值一样计算可为空列的返回值.例如,需要在表emp中查出所有比“WARD”提成(COMM)低的员工,提成为NULL(空 ...

  3. JavaSE-29 Java8的Lambda表达式

    概念说明 Lambda表达式是Java8提供的新特性,支持将代码块作为方法的参数. Lambda表达式支持使用简洁的代码创建只有一个方法的接口(函数式接口). 只包含一个方法的接口也称为函数式接口. ...

  4. 第1节 flume:4、离线项目处理的整个架构图;5、flume的基本介绍;

    第1节 flume:4.离线项目处理的整个架构图 辅助系统工具:flume,azkaban,sqoop. 在一个完整的离线大数据处理系统中,除了hdfs+mapreduce+hive组成分析系统的核心 ...

  5. 执行BarTender

    1.配置.btw模板 1.1.左侧创建“具名数据源” 1.2.条码属性,选择刚才的数据源 1.3.保存 2.配置.btin服务 2.1.点击 工具/Integration Builder” 2.2.创 ...

  6. POJ-1200-Crazy Search(字符串Hash)

    Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33142 Accepted: 9079 Descrip ...

  7. 2. CHARACTER_SETS

    2. CHARACTER_SETS CHARACTER_SETS表提供有关可用字符集的信息. 下表中的SHOW Name值对应于SHOW CHARACTER SET语句的列名. INFORMATION ...

  8. 如何用纯 CSS 创作一种有削铁如泥感觉的菜单导航特效

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/XqYroe 可交互视频教 ...

  9. c++_包子凑数

    标题:包子凑数 小明几乎每天早晨都会在一家包子铺吃早餐.他发现这家包子铺有N种蒸笼,其中第i种蒸笼恰好能放Ai个包子.每种蒸笼都有非常多笼,可以认为是无限笼. 每当有顾客想买X个包子,卖包子的大叔就会 ...

  10. scrollLeft属性设置无效的一个记录

    首先应该明确scrollLeft这个属性,只有当div中的内容长度大于当前div的长度是才能working,根据这个我我找到了一个很神奇的地方,而且我注意到这个${}连注释里面都能替换过来! 以下是正 ...