怒刷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 ...
随机推荐
- Castle IOC容器构建配置详解(二)
主要内容 1.基本类型配置 2.Array类型配置 3.List类型配置 4.Dictionary类型配置 5.自定义类型转换 一.基本类型配置 在Castle IOC的配置文件中,大家可能都已经注意 ...
- (剑指Offer)面试题17:合并两个排序的链表
题目: 输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然时按照递增排序的. 链表结点定义如下: struct ListNode{ int val; ListNode* next; }; 思 ...
- Oracle中decode方法的作用
DECODE(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值) 该函数含义如下: IF 条件=值1 THEN RETURN (翻译值1) ELSIF 条件=值2 THEN ...
- Python学习入门基础教程(learning Python)--5.2 Python读文件基础
上节简单的说明了一下Pyhon下的文件读写基本流程,从本节开始,我们做几个小例子来具体展示一下Python下的文件操作,本节主要是详细讲述Python的文件读操作. 下面举一个例子,例子的功能是读取当 ...
- MongoDB下载与安装
本节只针对MONGODB的安装进行介绍,具体mongodb的特点及优势可参考其他文件. 注意32位操作系统支持的最大文件为2GB,所以做大文件海量储存的朋友要选择64位的系统安装.开始我们的下载安装之 ...
- 15 Examples To Master Linux Command Line History
When you are using Linux command line frequently, using the history effectively can be a major produ ...
- cocos2dx libcurl
转自:http://www.himigame.com/curl-libcurl/878.html 本篇介绍使用libcurl编程的一般原则和一些基本方法.本文主要是介绍 c 语言的调用接口,同时也可能 ...
- Android输入输出系统之TouchEvent流程
一个是InputReader,一个是InputDispatcher.方法是dispatchTouch. 入口点是InputReader 的loopOnce方法. InputReader里面有个线程叫做 ...
- Android简单封装类似JQuery异步请求
在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...
- Android 和 PHP 之间进行数据加密传输
Android 和 PHP 之间进行数据加密传输 [代码] [Java]代码 1 mcrypt = new MCrypt(); 2 /* Encrypt */ 3 String encrypted = ...