HDU 1024 Max Sum Plus Plus(DP的简单优化)
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.
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std; const int INF=0x3f3f3f3f;
const int maxn=1e6+;
int f[maxn], pre[maxn], a[maxn]; int main()
{
//freopen("in.txt", "r", stdin);
int m,n;
while(cin>>m>>n)
{
for(int i=; i<=n; i++)
cin>>a[i]; memset(f, , sizeof(f));
memset(pre, , sizeof(pre)); int tmax;
for(int i=; i<=m; i++)
{
tmax=-INF;
for(int j=i; j<=n; j++)
{
f[j]=max(f[j-], pre[j-])+a[j];
pre[j-]=tmax; //注意pre的更新的顺序,pre[j-1]被使用后再更新pre[j-1]
tmax=max(tmax, f[j]);
}
}
cout<<tmax<<endl;
}
return ;
}
HDU 1024 Max Sum Plus Plus(DP的简单优化)的更多相关文章
- 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 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 (动态规划)
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 Plus(m个子段的最大子段和)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/ ...
- 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 ...
- HDU 1024 Max Sum Plus Plus(基础dp)
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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【动态规划求最大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
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- Redis和mysql数据怎么保持数据一致的?
需求起因 在高并发的业务场景下,数据库大多数情况都是用户并发访问最薄弱的环节.所以,就需要使用redis做一个缓冲操作,让请求先访问到redis,而不是直接访问MySQL等数据库. 这个业务场景, ...
- apache----------在apache环境下安装https支持
1.安装mod_ssl yum install mod_ssl2.修改阿帕奇的配置文件开启3.防火墙要开启443端口4.要把三个证书上传到阿帕奇配置文件下.5.更新 httpd.conf 配置文件 ...
- Js数组去重方法总结
//方法一 var arr = [1,23,1,1,1,3,23,5,6,7,9,9,8,5]; function removeDuplicatedItem(arr) { for(var i = 0; ...
- MODBUS协议解析中常用的转换帮助类(C#)
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
- SQL中内连接和外连接的区别
数据表的连接有: 1.内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2.外连接: 包括 (1)左外连接(左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表 ...
- 2018-2019-2 网络对抗技术 20165305 Exp2 后门原理与实践
常用后门工具 一.Windows获得Linux Shell 在Windows下使用ipconfig查看本机IP 使用ncat.exe程序监听本机的5305端口 在Kali环境下,使用nc指令的-e选项 ...
- webServices接口开发过程中项目启动遇到的错误org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 422; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-bean
org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 422; schema_reference.4: Failed to read ...
- Node.js基础学习二之POST请求
本篇介绍下 Node.js post 请求 需求: 用户登录,前端界面输入用户名和密码,点击登录请求后台验证,根据后台反馈的信息做出响应 前端: (1)使用form表单 (2)使用ajax异步请求 服 ...
- ASCII对应码表-键值(完整版)
ASCII对应码表-键值(完整版) Bin (二进制) Oct (八进制) Dec (十进制) Hex (十六进制) 缩写/字符 解释 0000 0000 00 0 0x00 NUL(null) 空字 ...
- 在mmdetection中跑通MaskRCNN
1.将数据集转化成COCO格式数据集 Kaggle->COCO: https://github.com/pascal1129/airbus_rle_to_coco/blob/master/1_s ...