Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 37418    Accepted Submission(s): 13363
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.

C/C++:

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std; const int MAX = 1e6 + ; int m, n, pre[MAX], dp[MAX], num[MAX], ans, j; int main()
{
while (~scanf("%d%d", &m, &n))
{
memset(dp, , sizeof(dp));
memset(pre, , sizeof(pre)); for (int i = ; i <= n; ++ i) scanf("%d", &num[i]);
for (int i = ; i <= m; ++ i)
{
ans = -INF;
for (j = i; j <= n; ++ j)
{
dp[j] = max(dp[j - ], pre[j - ]) + num[j];
pre[j - ] = ans;
ans = max(dp[j], ans);
}
// pre[j - 1] = ans;
} printf("%d\n", ans);
}
return ;
}

hdu 1024 Max Sum Plus Plus (动态规划)的更多相关文章

  1. HDU 1024 Max Sum Plus Plus [动态规划+m子段和的最大值]

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

  2. HDU 1024 Max Sum Plus Plus (动态规划 最大M字段和)

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

  3. HDU 1024 Max Sum Plus Plus (动态规划)

    HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "M ...

  4. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  5. HDU 1024 Max Sum Plus Plus(m个子段的最大子段和)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/ ...

  6. HDU 1024 Max Sum Plus Plus【动态规划求最大M子段和详解 】

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

  7. HDU 1024 Max Sum Plus Plus (动态规划、最大m子段和)

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

  8. HDU 1024 max sum plus

    A - Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  9. HDOJ 1024 Max Sum Plus Plus -- 动态规划

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Problem Description Now I think you have got an ...

随机推荐

  1. PHP array_product

    1.函数的作用:计算数组元素的乘积 2.函数的参数: @params array 3.例子: <?php $input = [false,true]; print_r(array_product ...

  2. PMP 德尔菲技术

    1.德尔菲技术,必须遵守以下几个规则: 每个专家只与主持人单线联系. 专家之间完全背靠背,更不能进行讨论.为保证专家提出独立见解,甚至需要把专家分散在不同的物理地点. 专家以匿名的书面形式提出意见. ...

  3. 数据结构1_C---单链表的逆转

    通过C语言函数实现单链表的逆转操作 例: 输入数据1,2,3,4 输出数据4,3,2,1 一共三个文件: 头文件stulist,h :链表结点的定义,结点指针的定义 源文件stulist.c:具体的实 ...

  4. 点击任何位置隐藏所需隐藏的元素 (无BUG/jQuery版)

    1>第一种分两步 1) :对document的click事件绑定事件处理程序,使其隐藏该div 2) :对div的click事件绑定事件处理程序,阻止事件冒泡,防止其冒泡到document,而调 ...

  5. 如何在CentOS6.4系统上安装KVM虚拟机

    CentOS6.4系统上安装KVM虚拟机   备注:以下操作说明是经过实验验证后总结出来的笔录,有需要的朋友可以进行参考,以下是基于VMware12.5.2虚拟机版本上安装的实验环境. 一.安装KVM ...

  6. 10.Nginx流行架构LNMP

    1.什么是LNMP架构 LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写.L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以 ...

  7. 2、Struts2开始深入

    一.Struts2的配置文件加载顺序 1 .进入过滤器[StrutsPrepareAndExecuteFilter]跟代码,可以看到对应的文件加载顺序 进入StrtsPrepareAndExecute ...

  8. 整理了适合新手的20个Python练手小程序

    100个Python练手小程序,学习python的很好的资料,覆盖了python中的每一部分,可以边学习边练习,更容易掌握python. 本文附带基础视频教程:私信回复[基础]就可以获取的 [程序1] ...

  9. Nginx在Window上简单的使用

    先上Nginx在Window上的基本常用指令: IP_hase也可以解决Session共享的问题:不过不推荐这样使用,建议使用 Memcache/redis来处理 session共享的问题 轮询还是权 ...

  10. SpringBoot之配置文件的注入

    @PropertySource&@ImportResource&@Bean @PropertySource:加载指定的配置文件: /** * 将配置文件中配置的每一个属性的值,映射到这 ...