hdu 1024 Max Sum Plus Plus (动态规划)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 37418 Accepted Submission(s): 13363
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.
Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
Process to the end of file.
Output the maximal summation described above in one line.
1 3 1 2 3
2 6 -1 4 -2 3 -2 3
6
8
C/C++:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std; const int MAX = 1e6 + ; int m, n, pre[MAX], dp[MAX], num[MAX], ans, j; int main()
{
while (~scanf("%d%d", &m, &n))
{
memset(dp, , sizeof(dp));
memset(pre, , sizeof(pre)); for (int i = ; i <= n; ++ i) scanf("%d", &num[i]);
for (int i = ; i <= m; ++ i)
{
ans = -INF;
for (j = i; j <= n; ++ j)
{
dp[j] = max(dp[j - ], pre[j - ]) + num[j];
pre[j - ] = ans;
ans = max(dp[j], ans);
}
// pre[j - 1] = ans;
} printf("%d\n", ans);
}
return ;
}
hdu 1024 Max Sum Plus Plus (动态规划)的更多相关文章
- HDU 1024 Max Sum Plus Plus [动态规划+m子段和的最大值]
Max Sum Plus Plus Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- 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 ...
- 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 --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- 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【动态规划求最大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 max sum plus
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- HDOJ 1024 Max Sum Plus Plus -- 动态规划
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Problem Description Now I think you have got an ...
随机推荐
- Vbox中unbuntu15.10与win10共享文件 及开启复制粘贴功能
学习linux,一直使用的是VMware虚拟机,虽然功能很强大,但总感觉页面切换很麻烦.所以转入Vbox的使用,下面介绍下unbuntu15.10与win10共享文件. 一 共享文件夹 步骤1:启动u ...
- Unix 线程共享创建进程打开的文件资源(1)
执行环境:Linux ubuntu 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 ...
- USACO环绕岛屿Surround the Islands 并查集 枚举暴力
题目描述 Farmer John has bought property in the Caribbean and is going to try to raise dairy cows on a b ...
- vue在一个方法执行完后再执行另一个方法
vue在一个方法执行完后执行另一个方法 用Promise来实现.Promise是ES6的新特性,用于处理异步操作逻辑,用过给Promise添加then和catch函数,处理成功和失败的情况 ES7中新 ...
- .net core跨平台应用研究-ubuntu core下配置.net core运行时
引言 年初研究了一阵子.net core跨平台应用,先后发表了几篇应用研究的文章.因工作原因,忙于项目上线,有一阵子没来博客园写文章了.最近项目基本收尾,抽空翻了下自己的博客,廖廖几篇文章,真让人汗颜 ...
- Java基础(39)Arrays.binarySearch方法
1.源码中可以看到,binarySearch方法调用了binarySearch0方法,binarySearch0方法才是标准的二分查找实现. 2.对于binarySearch0方法来说,注意最后的re ...
- fenby C语言 P10
if判断语句; if(a<0)→if(条件) if(){C语言语句} #include <stdio.h> int main() { int a=10; if(a>0) { p ...
- Java中数组操作 java.util.Arrays 类常用方法的使用
任何一门编程语言,数组都是最重要和常用的数据结构之一,但不同的语言对数组的构造与处理是不尽相同的. Java中提供了java.util.Arrays 类能方便地操作数组,并且它提供的所有方法都是静态的 ...
- Weblogic wls9_async_response 反序列化远程命令执行漏洞(CVE-2019-2725)复现
一. 漏洞简介 漏洞编号和级别 CVE编号:CVE-2019-2725,危险级别:高危,CVSS分值:9.8. CNVD 编号:CNVD-C-2019-48814,CNVD对该漏洞的综合评级为 ...
- 使用memset初始化int数组
memset()是一个来自于string库的函数,正规用法是初始化char类型的数组.因为char类型只占1个字节,memset按字节赋值后,会将char类型数组的所有元素变为你指定的值.但是4字节的 ...