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 compact

    1.函数的作用:将变量转成数组 2.函数的参数: @params string $varname1 @params string $varname2 ... @params array $varnam ...

  2. opencv实践::对象的提取

    问题描述 真实案例,对图像中对象进行提取,获取这样对象,去掉其它干扰和非目标对象. 解决思路 二值分割 + 形态学处理 +横纵比计算 #include <opencv2/opencv.hpp&g ...

  3. 学习 Antd Pro 前后端分离

    1.前言 最近学习reactjs ,前些年用RN开发过移动端,入门还算轻松.现在打算使用 Antd Pro 实现前后端分离.要使用Antd Pro这个脚手架,必须熟悉 umi.dva.redux-sa ...

  4. 楼上请让路 RoarCTF2019 Writeup

    Misc 签到题 RoarCTF{签到!!!} 黄金六年 文件尾部有一段base64,解码为16进制可以看到是一个压缩包 打开压缩包需要密码 使用pr抽帧 可以看到部分帧中有二维码,依次扫码即可得到k ...

  5. 图像处理 - ImageMagick 简单介绍与案例

    在客户端我们可以用 PhotoShop 等 GUI 工具处理静态图片或者动态 GIF 图片,不过在服务器端对于 WEB 应用程序要处理图片格式转换,缩放裁剪,翻转扭曲,PDF解析等操作, GUI 软件 ...

  6. git jenkins 基本部署 gitlab私有仓库

    从代码私有性方面来看,公司不希望员工获取到全部的代码,这个时候 GitLab 无疑是最佳的选择.但对于开源项目而言,GitHub 依然是代码托管的首选平台. 1.安装gitlab[root@gitla ...

  7. 百万年薪python之路 -- 内置函数

    内置对象(68个)第一部分 内置函数一共68个 一些可以重要性不高的内置函数,只需了解即可 all() any() bytes() callable() chr() ord() complex() d ...

  8. 利用SpringBoot+Logback手写一个简单的链路追踪

    目录 一.实现原理 二.代码实战 三.测试 最近线上排查问题时候,发现请求太多导致日志错综复杂,没办法把用户在一次或多次请求的日志关联在一起,所以就利用SpringBoot+Logback手写了一个简 ...

  9. 基于深度学习方法的dota2游戏数据分析与胜率预测(python3.6+keras框架实现)

    很久以前就有想过使用深度学习模型来对dota2的对局数据进行建模分析,以便在英雄选择,出装方面有所指导,帮助自己提升天梯等级,但苦于找不到数据源,该计划搁置了很长时间.直到前些日子,看到社区有老哥提到 ...

  10. jquery复习

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...