怒刷DP之 HDU 1024
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2015-09-05)
Description
Given a consecutive number sequence S 1, S 2, S 3, S 4 ... S x, ... S n (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ S x ≤ 32767). We define a function sum(i, j) = S i + ... + S j (1 ≤ i ≤ j ≤ n).
Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i 1, j 1) + sum(i 2, j 2) + sum(i 3, j 3) + ... + sum(im, j m) maximal (i x ≤ i y ≤ j x or i x ≤ j y ≤ j x is not allowed).
But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(i x, j x)(1 ≤ x ≤ m) instead. ^_^
Input
Process to the end of file.
Output
Sample Input
2 6 -1 4 -2 3 -2 3
Sample Output
8
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- const int SIZE = ;
- const int INF = 0x7ffffff0;
- long long DP[SIZE][];
- int S[SIZE];
- long long max(long long a,long long b);
- int main(void)
- {
- int n,m,i_0,i_1;
- long long box,ans,temp;
- while(scanf("%d%d",&m,&n) != EOF)
- {
- memset(DP,,sizeof(DP));
- ans = -INF;
- i_0 = ;
- i_1 = ;
- for(int i = ;i <= n;i ++)
- scanf("%d",&S[i]);
- for(int j = ;j <= m;j ++)
- {
- for(int i = ;i <= n;i ++)
- {
- DP[i][i_1] = i - < j ? -INF : DP[i - ][i_1];
- if(i == )
- {
- temp = -INF;
- for(int k = j - ;k < i;k ++)
- temp = max(temp,DP[k][i_0]);
- }
- else
- temp = temp > DP[i - ][i_0] ? temp : DP[i - ][i_0];
- DP[i][i_1] = (temp > DP[i][i_1] ? temp : DP[i][i_1]) + S[i];
- if(j == m)
- ans = ans > DP[i][i_1] ? ans : DP[i][i_1];
- }
- swap(i_0,i_1);
- }
- printf("%lld\n",ans);
- }
- }
- long long max(long long a,long long b)
- {
- return a > b ? a : b;
- }
怒刷DP之 HDU 1024的更多相关文章
- 怒刷DP之 HDU 1257
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 怒刷DP之 HDU 1160
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- 怒刷DP之 HDU 1260
Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 怒刷DP之 HDU 1176
免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 怒刷DP之 HDU 1087
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- 怒刷DP之 HDU 1069
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 怒刷DP之 HDU 1029
Ignatius and the Princess IV Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d &a ...
- [kuangbin 带你飞] DP专题——HDU - 1024
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- jpa 支持(sql)JDBC标准语句
=====================dao================================ package com.jb.xs.Dao.impl; import java.uti ...
- Dubbo远程调用服务框架原理与示例
Dubbo 是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring框架无缝集成. 主要核心部件: Remoting: 网络通信框架 ...
- The_Last_Geass
我在此立下最终的Flag,为了让它保持在第一条我不会再发任何说说:从吃晚饭开始心情就有些崩溃,感觉毫无希望.一直到现在三个多小时吧,想了很多写了很多也跑了两圈步,也许明白了些什么. 现在1月,距离省选 ...
- lua安装和简单使用
1.安装 下载地址:https://www.lua.org/download.html 编译之前要安装readline,直接用yum安装 yum -y install readline-devel n ...
- 小巧实用js倒计时
<script type="text/javascript"> var intDiff = parseInt(15); //倒计时总秒数量 functi ...
- jquery操作复选框(checkbox)
1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...
- 高分辨率 2x图像: -webkit-min-device-pixel-ratio 的常见值对照
-webkit-min-device-pixel-ratio的常见值对照 原文地址:http://zhangyaochun.iteye.com/blog/1816582 前言: 本文来自于对 http ...
- MySQL alter
1:删除列 ALTER TABLE [表名字] DROP [列名称] 2:增加列 ALTER TABLE [表名字] ADD [列名称] INT NOT NULL COMMENT '注释说明' 3: ...
- VPS之openVPN的安装配置
原文地址:http://www.blogjava.net/dongbule/archive/2010/11/01/336714.html 上次写的<VPS的购买和使用>中提到了openVP ...
- 学习理论之正则化(Regularization)与模型选择
一.引言 对于一个学习问题,可以假设很多不同的模型,我们要做的是根据某一标准选出最好的模型.例如,在多项式回归中,对于我们的假设模型,我们最要紧的是决定 k 到底取多少合适,能不能有一种方法可以自动选 ...