HDU 1024 DP Max Sum Plus Plus
题意:本题的大致意思为给定一个数组,求其分成m个不相交子段和最大值的问题。
kuangbin专题。
dp[i][j]=Max(dp[i][j-1]+a[j] , max( dp[i-1][k] ) + a[j] ) 0<k<j
注意可以换成一维数组。第一维i没有影响,我们要求dp[m][n],所以i维可以省去,每次保留前j-1个数之中最大的部分。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define clc(a,b) memset(a,b,sizeof(a))
int a[];
int dp[];
int maxn[];
int main()
{
int m,n;
while(~scanf("%d%d",&m,&n))
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
clc(dp,);
clc(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]);
}
}
printf("%d\n",maxx);
}
return ;
}
HDU 1024 DP Max Sum Plus Plus的更多相关文章
- HDU 1024:Max Sum Plus Plus(DP)
http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Problem Description Now I think you ...
- HDU 1024:Max Sum Plus Plus(DP,最大m子段和)
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 1024 A - Max Sum Plus Plus DP + 滚动数组
http://acm.hdu.edu.cn/showproblem.php?pid=1024 刚开始的时候没看懂题目,以为一定要把那n个数字分成m对,然后求m对中和值最大的那对 但是不是,题目说的只是 ...
- HDU 1003:Max Sum(DP,连续子段和)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 1003:Max Sum
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 1024 dp滚动数组
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...
- 【HDU 1003】 Max Sum
题 题意 需要在o(n)时间内,求最大连续的子序列的和,及其起点和终点. 分析 一种方法是一边读,一边维护最小的前缀和 s[i] ,然后不断更新 ans = max(ans,s[j] - s[i]), ...
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
随机推荐
- 3.8 spring - AbstractBeanDefinition 介绍
之前,我们已尽完成了xml 文档到 GenericBeanDefinition的转换, 也就是说,到这里,所有的配置都可以在GenericBeanDefinition 的实例中找到对应的配置. Gen ...
- Delphi逆向
Delphi反汇编内部字符串处理函数/过程不完全列表 名称 参数 返回值 作用 等价形式 / 备注 _PStrCat EAX :目标字符串 EDX :源字符串 EAX 连接两个 Pascal 字符串 ...
- KafkaSpout: PartitionManager的行为分析
KafkaSpout的核心逻辑都是由PartitionManager来实现的. 但是这个类实现时候需要考虑的东西有些多,0.92至0.93,至当前(2015.3.14)的master一直在变化.在这里 ...
- 建立Clojure开发环境-使用IDEA和Leiningen
OS: Mac OS X 10.10 IDEA 14.0.2 Community Edition 安装Leiningen 按照http://leiningen.org/的指南安装lein 阅读Lein ...
- Pie Charts
Default pie chart The default pie chart with no options set. Source Code $.plot('#placeholder', da ...
- HDU1412
大水题.. 求集合的并 /* */ #include<algorithm> #include<iostream> #include<string.h> #inclu ...
- nginux做反向代理配置文件
做反向代理的配置文件最好单独创建一个文件,然后在主配置文件中使用 include nginx-test.config; 这样的方式来导入. 配置代码如下: ## Basic reverse prox ...
- js团购倒计时
客户端代码可以看: http://www.zhangxinxu.com/wordpress/2010/07/%E5%9B%A2%E8%B4%AD%E7%B1%BB%E7%BD%91%E7%AB%99% ...
- (转)Decision Tree
Decision Tree:Analysis 大家有没有玩过猜猜看(Twenty Questions)的游戏?我在心里想一件物体,你可以用一些问题来确定我心里想的这个物体:如是不是植物?是否会飞?能游 ...
- 【POJ】3294 Life Forms
后缀数组. /* 3294 */ #include <iostream> #include <sstream> #include <string> #include ...