Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.

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的更多相关文章

  1. HDOJ 1024 Max Sum Plus Plus -- 动态规划

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Problem Description Now I think you have got an ...

  2. 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 ...

  3. hdu 1024 Max Sum Plus Plus (动态规划)

    Max Sum Plus PlusTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. 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 ...

  5. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  6. HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化

    题目链接:https://cn.vjudge.net/problem/HDU-1024 题意 给n, m和一个序列,找m个不重叠子串,使这几个子串内元素和的和最大. n<=1e6 例:1 3 1 ...

  7. Max Sum Plus Plus (动态规划) HDU1024

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1024 (http://www.fjutacm.com/Problem.jsp?pid=1375) 题意 ...

  8. max Sum(简单动态规划)

    http://acm.hdu.edu.cn/showproblem.php?pid=1003 / 给组测试数据 1 7 2 3 -4 -5 6 7 8 一个关键问题 : 什么时候将开始位置重新赋值 即 ...

  9. HDOJ-1003 Max Sum(最大连续子段 动态规划)

    http://acm.hdu.edu.cn/showproblem.php?pid=1003 给出一个包含n个数字的序列{a1,a2,..,ai,..,an},-1000<=ai<=100 ...

随机推荐

  1. TCP Nagle算法&&延迟确认机制

    TCP Nagle算法&&延迟确认机制 收藏 秋风醉了 发表于 3年前 阅读 1367 收藏 0 点赞 0 评论 0 [腾讯云]买域名送云解析+SSL证书+建站!>>> ...

  2. Linux内核哈希表分析与应用

        目录(?)[+]   Linux内核哈希表分析与应用 Author:tiger-johnTime:2012-12-20mail:jibo.tiger@gmail.comBlog:http:// ...

  3. guide dpdk

    Welcome to DPDK Guide! Contents: Setting up DPDK Important Prerequisites Setting up repositories Red ...

  4. XiaoKL学Python(D)argparse

    该文以Python 2为基础. 1. argparse简介 argparse使得编写用户友好的命令行接口更简单. argparse知道如何解析sys.argv. argparse 模块自动生成 “帮助 ...

  5. Scrapy框架学习笔记

    1.Scrapy简介 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网 ...

  6. Linux vps服务器国产面板wdcp的安装和使用方法

    对于大多数站长来说,稳定的服务器不可或缺,这是我做网站以来的深刻体会,因为之前我在网站运营方面因这个原因吃了很多亏.在这里说出,只希望朋友们不要像我一样.在网站优化过程中,服务器因素导致排名下滑,甚至 ...

  7. Servlet开发的三种方法

    第一种 实现 Servlet 接口,需要覆写 Servlet 的5个方法,并将ServletConfig对象保存到类级变量中 package app01a; import java.io.IOExce ...

  8. mysql 5.7 linux环境下解压安装

    在CentOS linux环境安装mysql 一般rpm(或者yum),预编译和源码安装. 如果采用rpm或者yum安装,mysql的数据文件一般存放在/var/lib/mysql目录下,也就是会把d ...

  9. CSS-表格特有属性和定位

    1.表格特有属性 1.边框合并 属性:border-collapse 取值: 1.separate 默认值,即分离边框模式 2.collapse 边框合并 2.边框边距 作用:设置单元格之间或单元格与 ...

  10. UVALive-7041(回文树

    题意:给你两个字符串,问你有多少对公共回文串. 思路:先对a字符串建回文树.然后再把b字符串加进去就好了. #include<cstdio> #include<cmath> # ...