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)
Total Submission(s): 34541 Accepted Submission(s): 12341
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 <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 1100000
#define INF 0x3f3f3f3f
int dp[MAXN];
int maxn[MAXN];
int a[MAXN];
int main()
{
int n,m;
std::ios::sync_with_stdio(false);
while(cin>>m>>n){
for(int i=;i<=n;i++){
cin>>a[i];
maxn[i]=;
dp[i]=;
}
dp[]=;
maxn[]=;
int maxx;
for(int i=;i<=m;i++){
maxx=-INF;
for(int j=i;j<=n;j++){
dp[j]=max(dp[j-]+a[j],maxn[j-]+a[j]);
maxn[j-]=maxx;
maxx=max(maxx,dp[j]);
}
}
cout<<maxx<<endl;
}
return ;
}
HDU 1024 Max Sum Plus Plus(基础dp)的更多相关文章
- 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 ...
- HDU 1024 Max Sum Plus Plus(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题目大意:有多组输入,每组一行整数,开头两个数字m,n,接着有n个数字.要求在这n个数字上,m块 ...
- 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
这题的意思就是取m个连续的区间,使它们的和最大,下面就是建立状态转移方程 dp[i][j]表示已经有 i 个区间,最后一个区间的末尾是a[j] 那么dp[i][j]=max(dp[i][j-1]+a[ ...
- 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 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
Max Sum Plus Plus Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
随机推荐
- python学习笔记二:流程控制
一.if else: #!/usr/bin/python x = int(raw_input('please input:')) if x >= 90: if x >= 95: print ...
- BFC相关知识
一.什么是BFC css布局主要采用盒子模型(BOX),元素的类型和 display 属性,决定了 Box 的类型,常见的盒子类型有两种: block-level box:display 属性为 bl ...
- Python全栈工程师(编码)
ParisGabriel Python 入门基础 补充: 主流3操作大系统 Windows: Winxp Win7 Win8 Win10 Unix: Solaris(SUN) IO ...
- HDU 4109 Instrction Arrangement(DAG上的最长路)
把点编号改成1-N,加一点0,从0点到之前任意入度为0的点之间连一条边权为0的边,求0点到所有点的最长路. SPFA模板留底用 #include <cstdio> #include < ...
- Java对字符串进行加密
package anli1; import java.util.Scanner; public class example { public static void main(String[]args ...
- CSS3的笔记总结
css3 就是css2 的一个升级版本.css2 是用来做效果渲染的,而css3 可以使做出来的效果更佳丰富. C3有兼容性问题,移动端支持稍微要好些. 坚持以下原则: ...
- 关系、关系模式、关系模型blablabla...
好久没碰<数据库系统概论>了,最近翻了翻发现好多专业名词都忘记了, 现在有空特地记录下. 名词解释 数据:数据就是数据库中存储的基本数据,比如学生的学号.学生的班级数据库:存放数据的仓库数 ...
- 股神小L [贪心]
题面 思路 股票题肯定是贪心或者$dp$啊 这个题比较$naive$,可以看出来你这里买股票的过程一定是能不买就不买,能卖就拣最贵的日子卖,而且时间不能倒流(废话= =||) 所以我们按照时间从前往后 ...
- http登陆时的密码加密
系统设计登陆页面的时候,需要谨慎.因为登陆数据是在网络上进行传输,很可能中途被拦截. 最好的登陆是使用https,这样网络传输是安全的.google,baidu,alibaba都使用https的方式. ...
- POJ -1679(次小生成树)模板
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions:34617 Accepted: 12637 D ...