HDOJ1024--Max Sum Plus Plus(动态规划)UnSolved
Given a consecutive number sequence S 1, S 2, S 3, S 4 ... S x, ... S n (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ S x ≤ 32767). We define a function sum(i, j) = S i + ... + S j (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(i 1, j 1) + sum(i 2, j 2) + sum(i 3, j 3) + ... + sum(i m, j m) maximal (i x ≤ iy ≤ j x or i x ≤ j y ≤ j x 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(i x, j x)(1 ≤ x ≤ m) instead. ^_^
InputEach test case will begin with two integers m and n, followed by n integers S 1, S2, S 3 ... S n.
Process to the end of file.
OutputOutput the maximal summation described above in one line.
Sample Input
1 3 1 2 3
2 6 -1 4 -2 3 -2 3
Sample Output
6
8
Hint
Huge input, scanf and dynamic programming is recommended. 若不做任何优化,并不考虑数据大小,仅考虑样例
#include<iostream>
#include<algorithm>
using namespace std;
int num[];
int dp[][];
int main(){
int n,m;
while(cin>>n>>m){
for(int i=;i<=m;i++){
cin>>num[i];
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int m=-;
for(int w=;w<j;w++){
m=max(dp[i-][w],m);
}
dp[i][j]=max(m,dp[i][j-])+num[j];
}
}
int ans=-;
for(int i=;i<=m;i++){
ans=max(ans,dp[n][i]);
}
cout<<ans<<endl;
}
return ;
}
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[];
int Max[];
int num[];
int main(){
int m,n;
while(cin>>m>>n){
int k;
for(int i=;i<=n;i++){
cin>>num[i];
}
memset(dp,,sizeof(dp));
memset(Max,,sizeof(Max));
int mmax; for(int i=;i<=m;i++){
mmax=-INT_MAX;
for(int j=i;j<=n;j++){
dp[j]=max(dp[j-],Max[j-])+num[j];
Max[j-]=mmax;
mmax=max(mmax,dp[j]);
}
}
cout<<mmax<<endl;
}
return ;
}
HDOJ1024--Max Sum Plus Plus(动态规划)UnSolved的更多相关文章
- HDOJ 1024 Max Sum Plus Plus -- 动态规划
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Problem Description Now I think you have got an ...
- HDU 1024 Max Sum Plus Plus [动态规划+m子段和的最大值]
Max Sum Plus Plus Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- hdu 1024 Max Sum Plus Plus (动态规划)
Max Sum Plus PlusTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1024 Max Sum Plus Plus (动态规划 最大M字段和)
Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...
- 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...
- HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化
题目链接:https://cn.vjudge.net/problem/HDU-1024 题意 给n, m和一个序列,找m个不重叠子串,使这几个子串内元素和的和最大. n<=1e6 例:1 3 1 ...
- Max Sum Plus Plus (动态规划) HDU1024
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1024 (http://www.fjutacm.com/Problem.jsp?pid=1375) 题意 ...
- max Sum(简单动态规划)
http://acm.hdu.edu.cn/showproblem.php?pid=1003 / 给组测试数据 1 7 2 3 -4 -5 6 7 8 一个关键问题 : 什么时候将开始位置重新赋值 即 ...
- HDOJ-1003 Max Sum(最大连续子段 动态规划)
http://acm.hdu.edu.cn/showproblem.php?pid=1003 给出一个包含n个数字的序列{a1,a2,..,ai,..,an},-1000<=ai<=100 ...
随机推荐
- jquery Jquery 遍历 获取设置 效果
speed: slow fast 毫秒 隐藏 显示 $(selector).hide(speed,callback) 隐藏. $(selector).show(speed,callback) 显示 $ ...
- C++中find_if
总结:find_if针对查找的对象中包含指针需要进行比较 find则更偏向于普通的数值或者字符比较 两者都可以应用于自定义的类,只需在类中重载==运载符 函数调用符()说白了其实就是代替函数指针,调用 ...
- IDEA 的 Edit 设置
1.设置鼠标悬浮提示 General -- Show quick documentation on mouse move 2.自动导包 3.设置显示行号和方法的间隔符 4.忽略大小写 4.设置取消单 ...
- iOS.Operation-on-ZipFile
Operation on ZipFile Reference 在Mac OS X和iOS中操作.zip文件(例如创建zip文件, 从zip文件中抽取数据): 1. http://stackoverfl ...
- javascript 高级程序设计 九
JS 面向对象的程序设计思想(1)深入理解JS对象 1.js的中没有OO语言中的'类'的概念.ECMAjs中把对象定义为:‘无序属性的集合,其属性可以包含基本值,对象或函数’. 2.ECMAScrip ...
- Luogu1070-道路游戏-动态规划
Solution 用对角线的前缀和快速进行转移,复杂度$O(N^3)$, 洛谷神机太快了$N^3$都能过 然而正解是单调队列优化, 能优化到$O(N^2)$,然而我弱得什么都不会 Code #incl ...
- C++基础教程(总结)
内容中包含 base64string 图片造成字符过多,拒绝显示
- tp5安装验证码
- Common tasks that you can perform with the Groovy Script test step
https://support.smartbear.com/readyapi/docs/soapui/steps/groovy.html Get test case object To obtain ...
- Visual code 搭建Vue项目
使用VS Code搭建Vue项目 1.安装 VScode 2..安装最新node.JS 2.安装cnpm镜像 淘宝镜像(node自带安装了npm,故不再安装) npm install -g cnpm ...