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/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35988 Accepted Submission(s): 12807
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. ^_^
Process to the end of file.
2 6 -1 4 -2 3 -2 3
8
Huge input, scanf and dynamic programming is recommended.
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<set>
#include<map>
#include<list>
#include<algorithm>
using namespace std;
typedef long long LL;
int mon1[]= {,,,,,,,,,,,,};
int mon2[]= {,,,,,,,,,,,,};
int dir[][]={{,},{,-},{,},{-,}}; #define INF 0x7fffffff//无穷大
#define max_v 1000010
int a[max_v];
int now[max_v];// now[j]:包含第j个元素的最大和
int pre[max_v];// pre[j]:前j个元素的最大和,不包括第j个元素
int main()
{
int n,m,maxx;
while(~scanf("%d %d",&m,&n))
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
memset(now,,sizeof(now));
memset(pre,,sizeof(pre));
for(int i=;i<=m;i++)//m个子段
{
maxx=-INF;
for(int j=i;j<=n;j++)
{
now[j]=max(now[j-]+a[j],pre[j-]+a[j]);
//now[j] 有两种来源,一种是直接在第i个子段后面加a[j],一种是a[j]单独成为一个子段
pre[j-]=maxx;//更新pre使得pre[j-1]是前j-1个中的最大子段和
maxx=max(now[j],maxx);
}
}
printf("%d\n",maxx);
}
return ;
}
HDU 1024 Max Sum Plus Plus(m个子段的最大子段和)的更多相关文章
- 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 ...
- 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 ...
- HDU 1024 Max Sum Plus Plus【DP,最大m子段和】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1024 题意: 给定序列,给定m,求m个子段的最大和. 分析: 设dp[i][j]为以第j个元素结尾的 ...
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- 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 ...
- HDU 1024 max sum plus
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- hdu 1024 Max Sum Plus Plus DP
Max Sum Plus Plus Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
- hdu 1024 Max Sum Plus Plus
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1024 Max Sum Plus Plus【DP】
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we ...
随机推荐
- Linux+Git命令
Linux 文件与目录 cd命令: $ cd [path] //path为路径名称,这只是常规语法 1 详细用法如下: $ cd /d //进入d盘 $ cd d: //进入d盘 $ cd D: // ...
- 使用itext导出pdf
导出pdf这个功能是在工作中遇到的,写这个功能的时候遇到了不少的问题,比如中文乱码,不显示的问题,这些问题在我不断的测试,研究后都一一解决了. 第一步,先导入所需要的jar包 第一个jar包是用于解决 ...
- JavaScript获取当前站点的域名和端口号
获取域名(第一种方法): document.hostname 获取域名(第二种方法): document.domin 获取端口号: location.port 获取主机+端口号: location.h ...
- Open Live Writer 安装和博客账号配置
打开Open Live Writer就像您的博客的Word一样.打开Live Writer是一个功能强大,轻量级的博客编辑器,允许您创建博客文章,添加照片和视频,然后发布到您的网站. Open Liv ...
- CF Dima and To-do List
B. Dima and To-do List time limit per test 1 second memory limit per test 256 megabytes input standa ...
- safari兼容时间格式
前提: 使用iview的DatePicker组件,保存时间后台接收时间戳 问题: safari中不支持2018-02-13这种格式转为时间戳会显示NaN 解决: new Date('2018/02/1 ...
- gulpfile配置
/** * 只包含合并压缩混淆,监听服务 */// 引入gulp模块var gulp = require('gulp'); // 引入其他模块var less = require('gulp-less ...
- .NET开源工作流RoadFlow-Bug修改-1.8.2表单验证时ueditor编辑非空验证无效
RoadFlow生成的表单,Ueditor编辑器不能进行非空验证的BUG修改: 1.修改控制器:WorkFlowFormDesignerController红框处: 2.修改js文件:Scripts/ ...
- .NET开源工作流RoadFlow-流程运行-运行时监控
流程实例参与者都可以随时查看流程实例的运行情况,如果是待办任务,则在待办事项列表的后面点查看,如果是已完成任务则可以在已办事项列表的后面点查看: 打开之后默认为列表方式显示流程的处理过程,还可以点图形 ...
- 《一马当先 O2O创业真人秀》阿里云创客+项目提交报名中
传统行业与互联网的相互融合,线上与线下的互通,正在掀起一股“互联网+”新风潮和创业热潮.支付宝钱包.快的打车.淘点点……这些耳熟能详的应用早已成为人们生活的一部分.而越来越多的“互联网+”创新项目,将 ...