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. WHERE谓词对索引使用的影响

    本篇博文只测试WHERE谓词对multi-column index使用的影响,主要篇幅是SQL代码+截图.详细内容请参考<Inside the SQL Server Query Optimize ...

  2. Java多线程实现

    1.继承Thread类,由于Java单继承特性,此方法并不推荐. 2.实现Runnable接口,代码如下 class MyThread implements Runnable { private St ...

  3. 关于 0xCCCCCCCC

    http://xingyunbaijunwei.blog.163.com/blog/static/76538067201281793111474/ http://stackoverflow.com/q ...

  4. iOS - (简单平移动画/弹出View的使用)

    在iOS 开发中,使用平移动画的频率越来越高,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,但我目前是使用较多的是平移动画,顺便也在此做一些小小的总结,大 ...

  5. SVN提交.a文件的方法

    选择菜单View-->Ignored Files,这样就会显示出ignored的文件,找到你要上传的.a文件,右键“Add”就可以了.

  6. 提高你的C#程序编码质量

    摘自陆敏技之<编写高质量代码:改善C#程序的157个建议>,编写C#程序代码时应考虑代码效率.安全和美观,可参考下述建议.想成为一名合格的搬砖工,牢记吧!! 基本语言要素 1.正确操作字符 ...

  7. javascript 正则表达式基础知识汇总

    正则表达式:对字符串中的信息实现查找.替换和提取操作.(不支持注释和空白,必须写在一行内)正则表达式的创建:包含在一对斜杠之间的字符(直接量语法)例如:var pattern = /s$/;     ...

  8. Excel将秒转换成标准的时间格式HH:MM:SS

    Excel将秒转换成标准的时间格式HH:MM:SS 比如120秒,转换成00:02:00 Excel公式为: =TEXT(A1/86400,"[hh]:mm:ss") A1为秒数据 ...

  9. Silverlight动画显示Line线

    目的:在silverlight中显示两点之间的连线,要求动画显示连线效果. 如果需实现动画效果不得不了解,Storyborad对象: Storyboard Silverlight   通过时间线控制动 ...

  10. log4cxx安装和使用

    log4cxx是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调试和审计,log4cxx是apache软件基金会的开源项目,基于APR实现跨平台支持 ...