状态:d(i,j)它代表前j划分数i部并且包括第一j最佳结果时的数。g(i,j)表示前j划分数i最好的结果时,段,g(m,n)结果,需要。

本题数据较大。需採用滚动数组。注意:这题int类型就够用了,开long long可能会TLE。

用滚动数组后,g[j]表示分成i段时最优结果,最后求出的g[n]即为结果

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll __int64
#define INF 0x3fffffff
using namespace std; const int MAX = 1e6+5;
int a[MAX];
int d[MAX];
int g[MAX]; int main()
{
int n,m;
//freopen("d:\\Test.txt","r",stdin);
while(~scanf("%d%d",&m,&n))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<=n;i++) d[i]=g[i]=0;
int temp=0;
for(int i=1;i<=m;i++)
{
for(int j=i;j<=n;j++)
{
d[j]=max(d[j-1],temp)+a[j]; //前j个数分为i-1段且包括第j个数的最佳结果
temp=g[j]; //分成i-1段时的最佳结果
g[j]=(i==j)? d[j]:max(g[j-1],d[j]); //j个数分成i段的最佳结果
}
temp=g[i]; //i个数分为i-1段的最佳结果
}
cout<<g[n]<<endl;
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU1024 Max Sum Plus Plus(DP)的更多相关文章

  1. HDU1024 Max Sum Plus Plus —— DP + 滚动数组

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Time Limit: 2000/1000 MS ...

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

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

  3. HDU1024 Max Sum Plus Plus 【DP】

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

  4. hdu1024 Max Sum Plus Plus 滚动dp

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

  5. HDU1024 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 ...

  6. hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行

    测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...

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

  8. Max Sum Plus Plus-HDU1024(dp)

    Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...

  9. hdu1003 Max Sum(经典dp )

      A - 最大子段和 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descr ...

随机推荐

  1. Team Foundation Server 2015使用教程--默认团队权限说明

  2. navicat如何导入sql文件

    工具--数据的传输--文件 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  3. Pro Aspnet MVC 4读书笔记(1) - Your First MVC Application

    Listing 2-1. The default contents of the HomeController class using System; using System.Collections ...

  4. Oracle按不同时间分组统计

    Oracle按不同时间分组统计 Oracle按不同时间分组统计的sql 如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- ...

  5. 标准差(standard deviation)和标准错误(standard error)你能解释一下?

    by:ysuncn(欢迎转载,转载请注明原始消息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根.而方差是随机变量期望的二次 ...

  6. 使用SeekBar办Android调色板

    1.接口布局xml代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...

  7. Eddy's mistakes(字母大小写转换)strlwr函数的应用

    Problem Description Eddy usually writes  articles ,but he likes mixing the English letter uses, for ...

  8. POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)

    解决报告 http://blog.csdn.net/juncoder/article/details/38159017 题目传送门 题意: 看到题目我就笑了.., 老师觉得这种两个学生不是一对: 身高 ...

  9. POJ1258 基础最小生成树

    本文出自:http://blog.csdn.net/svitter 题意:给出一个数字n代表邻接矩阵的大小,随后给出邻接矩阵的值.输出最小生成树的权值. 题解: prime算法的基本解法: 1.选择一 ...

  10. easyui dataBox 增加一天,减少一天

    <table> <tr> <td><a href="javascript:void(0)" class="easyui-link ...