怒刷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 ...
随机推荐
- Activity之间使用intent传递大量数据带来问题总结
转载:大飞 http://blog.csdn.net/rflyee/article/details/47441405 Activity之间使用Parcel传递大量数据产生的问题. Activity ...
- KMP算法初探
[edit by xingoo] kmp算法其实就是一种改进的字符串匹配算法.复杂度可以达到O(n+m),n是参考字符串长度,m是匹配字符串长度. 传统的算法,就是匹配字符串与参考字符串挨个比较,如果 ...
- 机器学习笔记之人工神经网络(ANN)
人工神经网络(ANN)提供了一种普遍而且实际的方法从样例中学习值为实数.离散值或向量函数.人工神经网络由一系列简单的单元相互连接构成,其中每个单元有一定数量的实值输入,并产生单一的实值输出. 上面是一 ...
- IE自动化 二(判断IP所在地)
该脚本用来访问一个url,并取出相应结果(该脚本用来通过淘宝API实现判断一个IP所在地) #定义要访问的URL $url="http://ip.taobao.com/service/get ...
- 如何自学Java
转自:http://www.360doc.com/content/12/0624/19/5856897_220191533.shtml JAVA自学之路 JAVA自学之路 一:学会选择 为了就业, ...
- C# 反射类型转换
/// <summary> /// 泛型类型转换 /// </summary> /// <typeparam name="T">要转换的基础类型 ...
- ReactNative学习实践--Navigator实践
离上次写RN笔记有一段时间了,期间参与了一个新项目,只在最近的空余时间继续学习实践,因此进度比较缓慢,不过这并不代表没有新进展,其实这个小东西离上次发文时已经有了相当大的变化了,其中影响最大的变化就是 ...
- 使用SurfaceView和MediaPlayer实现视频做为背景
场景:像我们在Uber应用开场,看到一一段视频作为開始.这样子让用户非常快投入应用使用的场景中去,这样的以视频作为开场的应用,我们是不是认为非常高大上呢,哈哈,事实上是使用了SerfaceView去载 ...
- IdHttpServer实现webservice
IdHttpServer实现webservice 朋友有个项目,通信协议使用HTTP,数据序列使用BIN(二进制).他不知道要选用何种技术方案. REST webservice是http+json ...
- 初次接触CodeSmith
说到开发效率的提高,代码生成器肯定是其中必不可少的重点.说到代码生成器,鼎鼎大名CodeSmith肯定是如雷贯耳. CodeSmith最大的特点是能够自定义模板(通俗的说就是想生成什么样就可以生成什么 ...