题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024

Max Sum Plus Plus

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

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(极光炫影)
题意:输入m,n,然后输入n个数。求最大连续m段和。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>using namespace std;const int oo = 0x7fffffff;
int a[1000005];
int dp[1000005];
int Max[1000005];int main()
{int m,n;while(~scanf("%d%d", &m, &n)){for(int i=1; i<=n; i++){scanf("%d", &a[i]);Max[i] = 0;dp[i] = 0;}int M;dp[0] = 0;Max[0] = 0;for(int i=1; i<=m; i++){M = -oo;for(int j=i; j<=n; j++){dp[j] = max(dp[j-1]+a[j], Max[j-1]+a[j]);//其中dp[j-1]表示的是以j-1结尾的元素i个子段的数和,Max[j-1]表示的是前j-1个元素中i-1个子段的数和Max[j-1] = M;//更新Max数组,下次循环用到。放在此处是为了实现Max[j-1]+a[j]中a[j]是一个独立的子段,那么此时就应该用的是i-1段M = max(dp[j], M);//更新M
            }}printf("%d\n",M);}return 0;
}

转载于:https://www.cnblogs.com/mengzhong/p/5058186.html

HDU 1024 Max Sum Plus Plus相关推荐

  1. HDU 1024 Max Sum Plus Plus 动态规划

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题目大意:n个数分成两两不相交的m段,求使这m段和的最大值. 解题思路:比较坑的点:n2 能过: ...

  2. HDU 1024 ~ Max Sum Plus Plus (DP + XJB优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题意:给你 n 个数字,你可以从中选m个子段(子段不能相交).让选出的子段和和最大. 题解:明显 ...

  3. hdu 1024 Max Sum Plus Plus(dp 最大m子段和)

    题意是输入m,n. m为你要求的子段个数,n为数据个数. 由于是很早的题型了,但是理解起来还是很是无力. 并于是用了三天来搞懂此类问题.发现网上大多代码无思路整个过程. 就大致讲解一下DP的整个思路. ...

  4. HDU - 1024 Max Sum Plus Plus 最大m段子段和+滚动数组优化

    给定n个数字,求其中m段的最大值(段与段之间不用连续,但是一段中要连续) 例如:2 5 1 -2 2 3 -1五个数字中选2个,选择1和2 3这两段. dp[i][j]从前j个数字中选择i段,然后根据 ...

  5. HDU 1024 Max Sum Plus Plus

    本题的大致意思为给定一个数组,求其分成m个不相交子段和最大值的问题. 读完题就能看出要用DP,但是因为m的范围没有限定,= =加上自己太菜不知道怎么写, 总之先膜拜大佬http://www.cnblo ...

  6. HDU 1244 Max Sum Plus Plus Plus

    虽然这道题看起来和 HDU 1024  Max Sum Plus Plus 看起来很像,可是感觉这道题比1024要简单一些 前面WA了几次,因为我开始把dp[22][maxn]写成dp[maxn][2 ...

  7. HDU.1003 Max Sum

    原题 HDU.1003 Max Sum 分类 动态规划 题意 计算从一个序列中最大连续子序列和.对应的起始元素和终止元素的位置. 输入/输出 要求与格式 样例数的确定 最开始一行开始输入样例数 每个样 ...

  8. HDUOJ 1024 Max Sum Plus Plus

    HDUOJ 1024 Max Sum Plus Plus 题目链接 Problem Description Now I think you have got an AC in Ignatius.L's ...

  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 AC ...

最新文章

  1. mysql右下角托盘中的图标_MFC下托盘图标的实现和托盘菜单。
  2. r语言和python-r语言和python
  3. 清理系统垃圾的快捷方法
  4. AM335x(TQ335x)学习笔记——GPIO关键驱动移植
  5. r语言读写word_R语言:在word中插入ggplot
  6. ieee754浮点数转换工具_关于JS浮点数运算不精确的原因和解决方案
  7. 滴滴货运公布首日战报 杭州成都订单破一万单
  8. SAP License:利润中心设计思路
  9. 山石网科发布山石云·景产品 安全运维管理进入SaaS模式
  10. Linux的哲学思想
  11. FTP服务器搭建及操作(一)
  12. 游戏开发之使用类封装双链表数据结构及双链表迭代器初版(C++基础)
  13. 烟雨在线要饭系统v2.0源码
  14. linux硬盘对拷ghost教程,用dd实现linux硬盘备份 GHOST
  15. 网络层(六)MAC地址与IP地址
  16. 格林尼治时间与本地时间转换
  17. 阿里云免费服务器搭建个人博客
  18. TNS service names ODBC dropdown box garbled, messed up, gibberish
  19. 机器学习(一):概述
  20. python语言诞生时间_Python语言诞生

热门文章

  1. 前端学习——这十本书一定要看
  2. ov5640帧率配置_《使命召唤 黑色行动 冷战》详细PC配置需求公布
  3. 活动目录安装|活动目录教程
  4. java中 一个等于号和两个等于号三个等号的区别?
  5. NodeJs string与base64互转
  6. 企业数字化转型“核心方法论”
  7. java 扔雪球_扔雪球攻略 真正实现扔雪球百发百中!
  8. 百度熊掌号php,百度熊掌号广受站长关注phpcm网站程序的熊掌号页面插件也火了!...
  9. 蓝牙开发那些事儿(10)——初识BLE
  10. Spring的XML解析中关于DTD的路径问题-