怒刷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 ...
随机推荐
- 使用maphilight高亮显示map的指定area
引用jquery.maphilight.js之后,调用如下方法: //obj参数是代表一个或者多个area的jQuery对象 function areaLight(obj) { var data = ...
- 错误"因为数据库正在使用,所以无法获得对数据库的独占访问权"的解决方案
今天在还原数据库的时候,提示"因为数据库正在使用,所以无法获得对数据库的独占访问权",无论我是重启数据库,还是重启计算机,都不能解决问题,多番尝试后,终于解决了该问题.现将引发该问 ...
- NSNotificationCenter需要注意的几个问题
NSNotificationCenter是iOS中常用的消息通知机制,不过在使用过程中有几点需要注意的问题. 直接贴Apple 的官方文档吧: A notification center delive ...
- spring含参数 环绕通知demo
题目:有一个懂得读心术的人需要完成两件事情:截听志愿者的内心感应和显示他们在想什么 <?xml version="1.0" encoding="UTF-8" ...
- canvas绘制直线和多边形基本操作
<!DOCTYPE HTML> <html lang="en"> <body> <canvas id="canvas" ...
- C++ Bit Fields
http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.71%29.aspx Note An unnamed bit field of widt ...
- 【转】知道创宇研发技能表v2.1
转自:http://blog.knownsec.com/Knownsec_RD_Checklist/v2.1.html# 知道创宇研发技能表v2.1 创建时间:2012/12/1 2013/4/26 ...
- 【M34】如何在同一个程序中结合C++和C
1.C++和C混合编程的时候,需要考虑产生的目标文件的兼容性. 2.名称重整,为什么要搞出名称重整? 连接器要求所有方法名必须独一无二.对于C语言,没问题.C++支持过载,也就是方法名相同,形参表不同 ...
- 从零开始学android开发-项目打包发布
右键项目 选择[android tools]-[export signed application package] 点击[next] 如果没有keystore可以选择[create new keys ...
- Class hierarchy of UIResponder as well as subclasses of UIView and UIControl
When you were dragging in your label and your button to this view, you were adding them as subviews. ...