Max Sum Plus Plus

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2015-09-05)

Description

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.

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

Each test case will begin with two integers m and n, followed by n integers S 1, S 2, S 3 ... S n
Process to the end of file. 
 

Output

Output the maximal summation described above in one line. 
 

Sample Input

1 3 1 2 3
2 6 -1 4 -2 3 -2 3
 

Sample Output

6
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的更多相关文章

  1. 怒刷DP之 HDU 1257

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  3. 怒刷DP之 HDU 1260

    Tickets Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  4. 怒刷DP之 HDU 1176

    免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  5. 怒刷DP之 HDU 1087

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  6. 怒刷DP之 HDU 1114

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  7. 怒刷DP之 HDU 1069

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  9. [kuangbin 带你飞] DP专题——HDU - 1024

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. Rule of write code with C# in Unity3d

    Good Practice 普通的Public变量可以在inspect里显示,变量是可以在inspect里赋值并realtime反映在被attach到的GameObject上的.注意经典public ...

  2. OpenStack tokens id获取测试

     

  3. 数据库 SQL :数据库三大泛式简谈

    相信,在学习数据库知识时,大家都会碰到这个概念问题:数据三大泛式,同时,在面试过程中,可能大部分面试官也会提及这个问题. 首先,看看维基百科对于三大泛式的定义: 数据库规范化,又称数据库或资料库的正规 ...

  4. MyEclipse 编写 ExtJS 卡死问题解决方法

    MyEclipse 8.6  在 jsp 中编写 ExtJS时,会出现卡死现象,让人甚是头疼.网上找了很多方法,折腾半天,还是不管用. 什么MyEclipse 优化,Validation 取消,MyE ...

  5. SQL Server-删除表中重复的记录!

    比如现在有一人员表  (表名:peosons)若想将姓名.身份证号.住址这三个字段完全相同的记录查询出来 select   p1.*   from   persons   p1,persons   p ...

  6. C# 仿制QQ弹出新闻消息框

    打开QQ的时候,QQ新闻弹出窗体在屏幕的右下角就会慢慢升起一个小窗口,占用的地方不大,可以起到提示的作用.下面就让我们来看看,怎样用系统API来轻松实现这个功能. API原型函数: bool Anim ...

  7. git常见问题

    一.设置git的user name和email: git config --global user.name "lei.li" git config --global user.e ...

  8. js中日期转换为时间戳

    function dateToTimestamp(date) { //方法一 var newDate = new Date(); newDate.setFullYear(date.substring( ...

  9. Xcode和IOS模拟器

    Xcode和IOS模拟器 目录 概述 Xcode常用操作 学会用Instrument IOS模拟器 概述 Xcode常用操作 整体缩进或者缩退 command+“[” .command+“]” 在同一 ...

  10. ChinaASP.Upload 错误 '80040002' You must add our copyright info

    ChinaASP.Upload 错误 '80040002' You must add our copyright info: http://www.chinaasp.com 修改 第一步:在“开始-运 ...