/*
这题还没有理解透彻。某个dalao也不写注释。只能自己理解了。。。
先求为i个元素(1<=i<=M)为一个区间的最大和,保证元素个数大于等于i个,递推到M个即可
借鉴原址:http://blog.csdn.net/java_wliang/article/details/14214303
欢迎讨论
*/
#include<cstdio>
#define maxn 1000005
#define inf 1<<30
#define Max(a,b) (a)>(b)?(a):(b)
int d[maxn],m[maxn],a[maxn];
void init(int n)
{
for(int i=; i<n; ++i)
d[i] = m[i] = ;
}
int main()
{
int n,M,ans;
while(~scanf("%d%d",&M,&n) && n+M)
{
init(n);
for(int i=; i<=n; ++i)
scanf("%d",&a[i]);
for(int i=; i<=M; ++i)
{
ans = -inf;
for(int j=i; j<=n; ++j)
{
d[j] = Max(d[j-]+a[j],m[j-]+a[j]);
m[j-] = ans;
ans = Max(ans,d[j]);
}
}
printf("%d\n",ans);
}
return ;
}

杭电1024----Max Sum Plus Plus的更多相关文章

  1. 杭电1003 Max Sum 【连续子序列求最大和】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max ...

  2. 杭电1003 Max Sum TLE

    这一题目是要求连续子序列的最大和,所以在看到题目的一瞬间就想到的是把所有情况列举出来,再两个两个的比较,取最大的(即为更新最大值的意思),这样的思路很简单,但是会超时,时间复杂度为O(n^3),因为有 ...

  3. 杭电 1003 Max Sum (动态规划)

    参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> ...

  4. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  5. hdu1003 1024 Max Sum&Max Sum Plus Plus【基础dp】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4302208.html   ---by 墨染之樱花 dp是竞赛中常见的问题,也是我的弱项orz, ...

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

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

  8. HDU 1024 max sum plus

    A - Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

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

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

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

随机推荐

  1. 水果(map的嵌套)

    夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了 ...

  2. Let the Balloon Rise <map>的应用

    Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the ...

  3. CF1029E

    一个看起来就不对的贪心居然是正解... 但仔细思考一下,这种贪心倒的确找不到反例.. 贪心思想:每次找出离根节点最远的点,然后由根节点向这个点的父节点连边,一直连到所有点都能被覆盖即可,这样构造出的一 ...

  4. Android Studio 删除多余的虚拟设备(Virtual Device)

    操作系统:Windows 10 x64 IDE:Android Studio 3.2.1 菜单:Tools > AVD Manager 在Android Virtual Device Manag ...

  5. 升级centos6.8内核

    1.查看默认版本:uname -r 2.更新nss 3.安装elrepo的yum源,升级内核需要使用elrepo的yum源,在安装yum源之前还需要我们导入elrepo的key rpm --impor ...

  6. Vue注意事项及用得较多的属性归纳

    1.prop是一个对象而不是字符串数组时,它包含验证要求.props: { // 基础类型检测 (`null` 意思是任何类型都可以) propA: Number, // 多种类型 propB: [S ...

  7. 类和JSP关系

    404的原因.除了路径问题,还有文件放置位置.比如如果文件在web-inf下面.浏览器是访问不到的

  8. Web的几种上传方式总结

    问题 文件上传在WEB开发中应用很广泛. 文件上传是指将本地图片.视频.音频等文件上传到服务器上,可以供其他用户浏览或下载的过程. 以下总结了常见的文件(图片)上传的方式和要点处理. 表单上传 这是传 ...

  9. IDEAL 中配置Tomcat的内存值

    -server -XX:PermSize=2048M -XX:MaxPermSize=4096m

  10. Eclipse Memory Analyzer

    先写一段可以制造堆溢出的代码 package com.test.jvm.oom; import java.util.ArrayList; import java.util.List; /** * @d ...