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 ...
随机推荐
- Qt 找不到rc.exe
Qt在window下出现编译错误: LINK : fatal error LNK1158: 无法运行“rc.exe” 解决: 找到rc.exe的放置路径,比如我的在下面: C:\Program Fil ...
- 概念理解-IO多路复用
epoll 是 Linux 内核为处理大批量文件描述符而作了改进的 poll,是 Linux 下多路复用 IO接口 select/poll 的增强版本 在 linux 的网络编程中,很长时间都在使用 ...
- VSCode 安装 code 命令
VSCode 提供 code 命令直接从命令行中打开文件目录,此时需要先安装 code 命令. 1.首先打开 VSCode 2.使用 command + shift + p (注意window 下使用 ...
- MySQL常用sql语句-----数据库操作
在数据库操作中,操作基本都是围绕增删改查来操作.简称CRUD C创建创建 R读取/检索查询 U Update修改 D删除删除 在数操作数据库时,所有的数据库语句都要以分号结束 数据库操作不区分大小写 ...
- chrome devtools tip(2)--自定义代码片段,构建你的工具箱
平常开发中,有些代码片段常常用到的,比如,获取 url 参数,rgb转16进制,打印下当前页面的性能数据,给所有的 span 加个样式, 防抖节流,fetch接口,类似 jquery这样的顺手 选择 ...
- 《HTML5+CSS3+JavaScript 从入门到精通(标准版)》学习笔记(二)
这是一个应用的例子,学以致用嘛 <!--这些代码我就直接放在了博客园的"页首Html代码"中,用于自定义博客,效果就是页面左上角的白色文字--> <p> & ...
- 一文理解java对象初始化顺序
例子 Talk is cheap, Show you the code! public class ParentClass { static int parentStaticField = 1; ...
- kafka里的一些管理脚本
kafka-server-start脚本 ------启动kafka server kafka-server-stop脚本 ------关闭kafka server kafka-topics脚本 -- ...
- 追查Could not get a databaseId from dataSource
Mybatis 创建连接池的时候报错: ERROR 2017-03-15 00:44:50,333 commons.JakartaCommonsLoggingImpl:38 Could not get ...
- Ubuntu 14.04 sudo免密码的方法| sudo不需要密码
Ubuntu 14.04 sudo免密码的方法| sudo不需要密码 cd /etc/sudoers.d sudo touch nopasswd4sudo sudo vi nopasswd4sudo ...