hdu1024 Max Sum Plus Plus[降维优化好题(貌似以后可以不用单调队列了)]
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28136 Accepted Submission(s): 9810
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<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1e6+;
int n,m,a[N];
//int f[N][N];
int f[N],maxn[N];
int main(){
while(~scanf("%d%d",&m,&n)){
memset(f,,sizeof f);
memset(maxn,,sizeof maxn);
for(int i=;i<=n;i++) scanf("%d",a+i);
/*for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
f[i][j]=f[i-1][j]+a[i];
for(int k=1;k<i;k++){
f[i][j]=max(f[i][j],f[k][j-1]+a[i]);
}
}
}
printf("%d\n",f[n][m]);*/
int nowans=;
for(int j=;j<=m;j++){
nowans=-1e9;
for(int i=j;i<=n;i++){
f[i]=max(f[i-],maxn[i-])+a[i];
maxn[i-]=nowans;
nowans=max(nowans,f[i]);
}
}
printf("%d\n",nowans);
}
return ;
}
hdu1024 Max Sum Plus Plus[降维优化好题(貌似以后可以不用单调队列了)]的更多相关文章
- HDU1024 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 ...
- [Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列)
[Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列) 题面 两个人玩游戏,共进行t轮,每人每轮从[-k,k]中选出一个数字,将其加到自己的总分中.已 ...
- 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 ...
- HDU1024 Max Sum Plus Plus —— DP + 滚动数组
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Time Limit: 2000/1000 MS ...
- 洛谷P2900 [USACO08MAR]土地征用Land Acquisition(动态规划,斜率优化,决策单调性,线性规划,单调队列)
洛谷题目传送门 用两种不一样的思路立体地理解斜率优化,你值得拥有. 题意分析 既然所有的土地都要买,那么我们可以考虑到,如果一块土地的宽和高(其实是蒟蒻把长方形立在了平面上)都比另一块要小,那么肯定是 ...
- HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化
题目链接:https://cn.vjudge.net/problem/HDU-1024 题意 给n, m和一个序列,找m个不重叠子串,使这几个子串内元素和的和最大. n<=1e6 例:1 3 1 ...
- hdu1024 Max Sum Plus Plus的另一种解法
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1024 http://www.51nod.com/onlineJudge/questionCode.htm ...
- hdu1024 Max Sum Plus Plus
动态规划,给定长度为n(≤1e6)的整数数组和整数m,选取m个连续且两两无交集的子区间,求所有方案中使得区间和最大的最大值. dp[i][j]表示结束位置(最后一个区间最后一个元素的位置)为i且选取区 ...
随机推荐
- 关于Cocos2d-x中监听物体不超越边界的解决方案
写一个监听器 touchlistener->onTouchMoved = [this](Touch* pTouch, Event*) { auto delta = pTouch->getD ...
- Ubuntu13.04下Eclipse中文乱码解决
参考:http://www.linuxidc.com/Linux/2011-12/50056.htm baoyu@baoyu:~$ gedit /var/lib/locales/supported.d ...
- poj2513(无向图判欧拉路)
链接:id=2513">点击打开链接 题意:一堆木棍左右两端涂有颜色,同样颜色的能够连接在一起,问全部木棍是否能都连上 代码: #include <map> #includ ...
- 【Java集合的详细研究7】Set和List 的关系与区别
两个接口都是继承自Collection. List (inteface) 次序是List 的最重要特点,它确保维护元素特定的顺序. --ArrayList 允许对元素快速随机访问. --LinkedL ...
- 不错的源码演示:admin5源码
admin5源码官网:http://down.admin5.com/ 集资讯,源码,字体,itchat于一体的网站,可以下载喔! 实际项目中可以用得到.
- js中页面跳转(href)中文参数传输方式
编码: escape(参数); 解码: unescape(参数);
- c++ String 大小写转化
string toUpperString(string str) { transform(str.begin(), str.end(), str.begin(), (int (*)(int))toup ...
- MathTyp使用过程的几个问题
最近毕业季,人们又开始了一波论文恐惧症了.每天都在不断地改来改去,格式还是不符合要求,头疼得要死.不仅如此,还发现公式是越改越乱,牵一发而全身,其它地方动一点,整个版面全都乱了,人都要抓狂了.知道你的 ...
- Windows网络编程Internet Gopher了解下
Gopher:中文译“地鼠”,是迪士尼卡通人物之一(谷佛). 英文原义:The Internet Gopher Protocol 中文释义:(RFC-1436)网际Gopher协议 该系统是在明尼苏达 ...
- Windows路径操作API函数学习
前言 在VC++开发过程中,经常需要用到一些路径操作,比如拼需要的文件路径,搜索路径中的内容等等.Windows提供了一套关于路径操作的API帮助我们更好的执行这些操作. 路径截断与合并API Pat ...