Max Sum Plus Plus-HDU1024(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.
2 6 -1 4 -2 3 -2 3
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream> using namespace std;
#define N 1000010
#define INF 0xfffffff
int dp[N];
int M[N];
int Max;
int a[N]; int main()
{
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
dp[i]=;
M[i]=;
}
dp[]=;
M[]=;
for(int i=;i<=m;i++)
{
Max=-INF;
for(int j=i;j<=n;j++)
{
dp[j]=max(dp[j-]+a[j],M[j-]+a[j]);
M[j-]=Max;
Max=max(Max,dp[j]);
}
}
printf("%d\n",Max);
}
return ;
}
Max Sum Plus Plus-HDU1024(dp)的更多相关文章
- 【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]
[题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plu ...
- HDU1024 Max Sum Plus Plus 【DP】
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu1024 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 Plus(DP)
http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Problem Description Now I think you ...
- 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的简单优化)
Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...
- Max Sum—hdu1003(简单DP) 标签: dp 2016-05-05 20:51 92人阅读 评论(0)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 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 ...
- HDU1024 Max Sum Plus Plus(dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 #include<iostream> #include<vector> #i ...
- HDU 1024 Max Sum Plus Plus 简单DP
这题的意思就是取m个连续的区间,使它们的和最大,下面就是建立状态转移方程 dp[i][j]表示已经有 i 个区间,最后一个区间的末尾是a[j] 那么dp[i][j]=max(dp[i][j-1]+a[ ...
随机推荐
- iOS猜拳游戏源码
利用核心动画和Quartz2D做的一个小游戏.逻辑十分简单. 源码下载:http://code.662p.com/<ignore_js_op> 详细说明:http://ios.662p.c ...
- uva1336 Fixing the Great Wall
用到了kase避免memset超时 #include<cstdio> #include<cstring> #include<cmath> #include<a ...
- billu_b0x靶场刷题
https://www.vulnhub.com/ 里面有很多安全环境,只要下载相关镜像,在虚拟机上面搭建运行就可以练习对应靶场了. 第一步.信息收集 nmap扫描内网开放80端口的存活主机 nmap ...
- JavaSE-31 Java正则表达式
概述 正则表达式是一个强大的字符串处理工具,可以实现对字符串的查找.提取.分割.替换等操作. String类的几个方法需要依赖正则表达式的支持. 方法 方法说明 boolean matches(Str ...
- 《3+1团队》【Alpha】Scrum meeting 5
项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 3+1团队 团队博客地址 https://home.cnblogs.com/u/3-1group ...
- mysql的sql语句练习的2个网址
sql语句练习: https://blog.csdn.net/mrbcy/article/details/68965271 完成. https://blog.csdn.net/flycat296/ar ...
- koa源码解读
koa是有express原班人马打造的基于node.js的下一代web开发框架.koa 1.0使用generator实现异步,相比于回调简单和优雅和不少.koa团队并没有止步于koa 1.0, 随着n ...
- 12scrapy_redis
一.简介 1.redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zse ...
- [JOYOI] 1071 LCIS
拖了好久的LCIS f[i][j]表示a串前i个,b串以b[j]结尾的LCIS长度. 转移时考虑a[i]和b[j]是否相等,如果不等: 那么既然是以j结尾,说明a串前i-1位有一个字符和b匹配了,所以 ...
- thinkphp5实现文件上传
原理:通过form表单的enctype = "multipart / form-data"属性将文件临时放在htdocs文件夹的tmp目录下,再通过后台的程序将文件保存在自己设定的 ...