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?pid=1024
Description
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. ^_^
Input
Process to the end of file.
Output
Output 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
8
HINT
题意
给你n个数,让你选择连续的M段,让你得到最大值
题解:
简单的想一想,dp[i][j]表示,前j个数,我选i段的最大值,那么转移方程,dp[i][j]=max(dp[i][j-1]+a[j],dp[i-1][k]+a[j])
然后滚动数组优化一下
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000005
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
} int dp[maxn+];
int mmax[maxn+];
int a[maxn+];
int main()
{
int n,m;
int i,j,mmmax;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
mmax[i]=;
dp[i]=;
}
dp[]=;
mmax[]=;
for(i=;i<=m;i++)
{
mmmax=-inf;
for(j=i;j<=n;j++)
{
dp[j]=max(dp[j-]+a[j],mmax[j-]+a[j]);
mmax[j-]=mmmax;
mmmax=max(mmmax,dp[j]);
}
}
printf("%d\n",mmmax); }
return ;
}
hdu 1024 Max Sum Plus Plus DP的更多相关文章
- 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】
		
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)
		
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
 - HDU 1024   max sum plus
		
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
 - HDU 1024 Max Sum Plus Plus【动态规划求最大M子段和详解 】
		
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
 - hdu 1003  MAX SUM 简单的dp,测试样例之间输出空行
		
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
 
随机推荐
- [Leetcode] N-Queens 系列
			
N-Queens 系列题解 题目来源: N-Queens N-Queens II N-Queens The n-queens puzzle is the problem of placing n qu ...
 - linux系统分区参考
			
UPDATE: update is used to download package information from all configured sources. UPGRADE: upgrad ...
 - webstrom 使用git
			
1.首先进入码云创建项目 2.创建成功,复制https地址,打开webstrom,选择git,填入https的地址 3.下载完成,打开项目,新建一个测试测HTML文件,点击右键,选择git,再选择ad ...
 - Tutorial 7: Schemas & client libraries
			
转载自:http://www.django-rest-framework.org/tutorial/7-schemas-and-client-libraries/ Tutorial 7: Schema ...
 - 简约而不简单的Django
			
本文面向:有python基础,刚接触web框架的初学者. 环境:windows7 python3.5.1 pycharm专业版 Django 1.10版 pip3 一.Django简介 百度百 ...
 - python_线程、进程和协程
			
线程 Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元. #!/usr/bin/env python #coding=utf-8 __author__ = 'yinjia' i ...
 - POJ 1661 Help Jimmy(二维DP)
			
题目链接:http://poj.org/problem?id=1661 题目大意: 如图包括多个长度和高度各不相同的平台.地面是最低的平台,高度为零,长度无限. Jimmy老鼠在时刻0从高于所有平台的 ...
 - beego学习笔记(4):开发文档阅读(6)
			
beego的响应流程: 1.监听的端口接收数据,默认是8080端口. 2.用户请求到达8080端口后,开始数据处理流程. 3.初始化CONTEXT对象.判断是否是WEBSOCKET请求,如果是,设置I ...
 - hdu 5202(DFS)
			
Rikka with string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
 - Spring 中Bean的装配方式
			
最近又买了一本介绍SSM框架的书,是由黑马程序员编写的,书上讲的很好理解,边看边总结一下.主要总结一下bean的装配方式. Bean的装配可以理解为依赖系统注入,Bean的装配方式即Bean依赖注入的 ...