题意:求一个数组中 M 段的 最大和

没看明白怎么搞得

抽空来看,写的不赖

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = + ;
int dp[N], num[N], pre[N];
int main()
{
int m, n;
while (scanf("%d%d", &m, &n) != EOF)
{
for (int i = ; i <= n; i++)
{
scanf("%d", &num[i]);
}
memset(pre, , sizeof(pre));
memset(dp, , sizeof(dp));
int ans = -INF, maxn;
for (int i = ; i <= m; i++)
{
maxn = -INF;
for (int j = i; j <= n; j++)
{
dp[j] = max(dp[j - ], pre[j - ]) + num[j];
pre[j - ] = maxn;
maxn = max(maxn, dp[j]);
}
//if (ans < maxn)
// ans = maxn;
}
printf("%d\n", maxn);
} return ;
}

HDU1024Max Sum Plus Plus(M段最大和)的更多相关文章

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

  2. uva10827-Maximum sum on a torus(矩阵最大和的变形)

    题目;uva10827-Maximum sum on a torus(矩阵最大和的变形) 题目大意:就是uva108的变形,矩阵能够连通,就是能够从后面连到前面.这里把矩阵复制三遍,然后又一次生成一个 ...

  3. HDU 1024 (不重叠m段最大和) Max Sum Plus Plus

    题解是看的这里的: http://www.acmerblog.com/hdu-1024-Max-Sum-Plus-Plus-1276.html 当前这个状态是dp[i][j],i 表示当前的段,j表示 ...

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

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

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

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

  6. HDU1024 多段最大和 DP

    题目大意: 在n个数,求不重复的m段中的数据总和的最大值 令dp[i][j]表示将前j个数分成 i 段时得到的最大值(必取到第 j 个数) 状态转移可列为 dp[i][j]=Max(dp[i][j-1 ...

  7. 最大m段子段和 Day9 - E - Max Sum Plus Plus HDU - 1024

    Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we ...

  8. 剑指Offer - 九度1372 - 最大子向量和(连续子数组的最大和)

    剑指Offer - 九度1372 - 最大子向量和(连续子数组的最大和)2013-11-23 16:25 题目描述: HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天JOBDU测试组开完会后, ...

  9. K - Max Sum Plus Plus

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

随机推荐

  1. 处理Linux下subversion尝试连接自建的VisualSVN server报“Key usage violation in certificate has been detected”错误的问题

    在Linux下使用subversion尝试链接VisualSVN server搭建的svn库,可能会报下面错误, svn: OPTIONS of 'https://server.domain.loca ...

  2. nios II--实验6——串口硬件部分

    串口 硬件开发 新建原理图 打开Quartus II 11.0,新建一个工程,File -> New Project Wizard…,忽略Introduction,之间单击 Next> 进 ...

  3. MSSQL 问题集锦

    [1]关于SQL Server数据库连接字符串的特殊参数说明 MultipleActiveResultSets和Mars_Connection同义,指定此数据库连接是否复用数据库内已建立的相同用户的连 ...

  4. C# Cut Line Bressenham Algorithm

    using System; using System.Drawing; using System.Windows.Forms; namespace CutLine { static class Pro ...

  5. python3.4 build in functions from 官方文档 翻译中

    2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python i ...

  6. hwclock 显示或设置CMOS时间

    显示或设置CMOS时间 hwclock [options] 选项 -r               默认选项,读取并打印CMOS时间 -s               将CMOS时间设置为系统时间 - ...

  7. 检查URL地址脚本

    方法一: [root@Centos-6 script]# vi check_url_01.sh #!/bin/sh #this script is created by nulige #check u ...

  8. Android中this、super的区别

    转载:http://blog.csdn.net/dyllove98/article/details/8826232 在Java中,this通常指当前对象,super则指父类的.当你想要引用当前对象的某 ...

  9. Sublime Text 3前端开发常用优秀插件介绍

    . 首页 博客园 联系我 前言:关于Sublime Text 3. Package Control插件管理. Package Control使用方法/安装Emmet插件. Emmet插件. JsFor ...

  10. java 数据绑定的几种方式及相关注意事项-持续更新

    spring mvc 中会遇到各种数据绑定,有些不常用的,但是千万不要觉得不可以,没有什么是不可以的,只要能够想到,就可以. 数据绑定方式: 1. 注意: 当数据为包装类型的数字型时,如果Long h ...