HDU_1024_dp
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24252 Accepted Submission(s): 8312
Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767). We define a function sum(i, j) = Si + ... + Sj (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(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im, jm) maximal (ix ≤ iy ≤ jx or ix ≤ jy ≤ jx 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(ix, jx)(1 ≤ x ≤ m) instead. ^_^
Process to the end of file.
2 6 -1 4 -2 3 -2 3
8
Huge input, scanf and dynamic programming is recommended.
#include<cstdio>
#include<iostream>
#include<malloc.h>
#include<cstring>
#include<map>
#include<string>
using namespace std;
#define LL long long
#define INF 0x7fffffff int value[];
LL dp[];
LL maxn[]; int main()
{
int m,n,num;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(dp,,sizeof(dp));
memset(maxn,,sizeof(maxn));
for(int i=; i<=n; i++)
scanf("%d",&value[i]);
LL ans=;
LL temp;
for(int i=; i<=m; i++)
{
temp=-INF;
for(int j=i; j<=n; j++)
{
dp[j]=max(dp[j-],maxn[j-])+value[j];
maxn[j-]=temp;
temp=max(temp,dp[j]);
}
//cout<<dp[0][3]<<endl; }printf("%I64d\n",temp);
}
return ;
}
HDU_1024_dp的更多相关文章
随机推荐
- 云计算VDI相关职位招聘
中电科华云信息技术有限公司是中国优秀的云计算方案提供商和服务商之中的一个.公司依托中国电子科技集团公司,实施"自主.可信.定制.服务"的差异化发展战略,以实现自主创新的技术研发.自 ...
- 5 shell命令之tr
这是一个奇妙的命令. tr的全拼就是translate,即翻译.有趣的是我们能够制定规则进行翻译.使用方法例如以下: tr [option] set1 [set2] tr从标准输入接受输入.然后将结 ...
- android 加密手机完毕后待机两分钟出现有频率的杂音
这个音效是code里面主动加的,是为了提醒end user输入PIN的一个提示音,也标志着加密手机动作的完毕. 详细位置是在alps\packages\apps\Settings\src\com\an ...
- vuejs快速入门
参考链接:http://www.cnblogs.com/keepfool/p/5619070.html
- 三分钟迁移Spring boot工程到Serverless
前言 Spring Boot已成为当今最流行的Java后端开发框架,典型的应用方式是在云上购买一台虚拟机,每天24小时在上面运行Java程序,在这种情况下,用户必须维护自己的虚拟机环境,而且按照包月包 ...
- vue iview Select bug,在低版本浏览器中报错
iview是个好东西,今天第一次试用,用来做了一个app,但是在安卓5.1各种报错啊,头痛的是不知道具体哪行代码错了,总是报错undefined is not a function. 倒腾了半天,原来 ...
- Bootstrap popover源码分析
/* ======================================================================== * Bootstrap: popover.js ...
- Python Tricks(十九)—— switch 的实现
python 原生语法不支持 switch,体现了 Python 大道至简的设计思路,有时为了避免啰嗦的 if elif等判断语句,我们可以用字典来代替 switch 的各分支,也即建立表达式和操作的 ...
- 洛谷P1155 双栈排序——思路题
题目:https://www.luogu.org/problemnew/show/P1155 思路... 看博客:https://www.cnblogs.com/Narh/p/9213825.html ...
- 杂项-Java:JSP
ylbtech-杂项-Java:JSP 1.返回顶部 1. JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Micros ...