http://acm.hdu.edu.cn/showproblem.php?pid=1024

Max Sum Plus Plus

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 ≤ jxor 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.

 
题意:将一串数字分成m段子序列,求最大可能达到的总和。
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 1000005
#define INF -1000000000
int num[N],dp[N],mmax[N];
/*
状态DP[i][j]
前j个数可以分成i组的和的最大值
DP[i][j]=max(dp[i][j-1]+num[j], max( dp[i-1][k] )+num[j]),0<k<j;
dp[i][j-1]是把num[j]加入到前面的一个组,
max(dp[i-1][k])+num[j]是把num[j]重新分在另一个组里面,
而max(dp[i-1][k])是分成i-1个组时候的和的最大值
开一个mmax数组每次都可以保存分成i-1个组的时候使用前j-1个数时候最大值
时间复杂度O(mn)
*/
int main()
{
int n,m;
while(~scanf("%d%d",&m,&n)){
for(int i=;i<=n;i++){
scanf("%d",num+i);
}
memset(dp,,sizeof(dp));
memset(mmax,,sizeof(mmax));
int ans;
for(int i=;i<=m;i++){
ans=INF;
for(int j=i;j<=n;j++){
dp[j]=max(dp[j-],mmax[j-])+num[j];
mmax[j-]=ans;
ans=max(dp[j],ans);
}
}
cout<<ans<<endl;
}
return ;
}

2016-06-21

HDU 1024:Max Sum Plus Plus(DP)的更多相关文章

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

  2. HDU 1024 Max Sum Plus Plus(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题目大意:有多组输入,每组一行整数,开头两个数字m,n,接着有n个数字.要求在这n个数字上,m块 ...

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

  4. hdoj Max Sum Plus Plus(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题意:----最大M子段和问题给定由 n个整数(可能为负整数)组成的序列a1,a2,a3,……, ...

  5. HDU1024 Max Sum Plus Plus(dp)

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

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

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

  8. HDU 1003:Max Sum(DP,连续子段和)

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

  9. HDU 1003:Max Sum

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

随机推荐

  1. Hadoop学习(3)-- 安装1.x版本

    Hadoop有三种安装模式,分别为单机模式.伪分布式模式和完全分布式模式(集群模式).本文安装版本是hadoop-1.1.2,hadoop-2.x版本安装请参考:http://www.cnblogs. ...

  2. CentOS安装NodeJS v0.10.25 + Express

    安装必需组件 yum -y install gcc make gcc-c++ openssl-devel wget cd ~wget http://nodejs.org/dist/v0.10.25/n ...

  3. c++怎么将一个类,拆分出接口类,和实现类

    还拿上一遍中定义的GradeBook类来实现: #include <iostream> using std::cout; using std::endl; #include <str ...

  4. Eclipse Ctrl+Tab Alt+/ 快捷键

    原来Eclipse的Next Editor 快捷键是 Ctrl+Tab 但是后几个版本将这个快捷键改为Ctrl+F6 了 在Keys设置下面 搜索 NextEditor 将其设置回来即可 同样 原来C ...

  5. @Transactional

    转载请标明出处:http://blog.csdn.net/cuker919/archive/2010/10/21/5957209.aspx Spring事务的传播行为 在service类前加上@Tra ...

  6. 暴力枚举-数长方形(hdu5258)

    数长方形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. nyist 599 奋斗的小蜗牛

    http://acm.nyist.net/JudgeOnline/problem.php?pid=599 奋斗的小蜗牛 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 ...

  8. [原创]java WEB学习笔记87:Hibernate学习之路-- -映射 继承关系(subclass , joined-subclass,union-subclass )

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  9. Java基础(62):Eclipse调试(Debug)的10条技巧(转)

    在看这篇文章前,我推荐你看一下Eclipse 快捷键手册 先提三点 不要使用System.out.println作为调试工具 启用所有组件的详细的日志记录级别 使用一个日志分析器来阅读日志 1.条件断 ...

  10. Java获取当前内存及硬盘使用情况

    import java.io.File; import java.lang.management.ManagementFactory; import com.sun.management.Operat ...