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的更多相关文章
随机推荐
- hdu1863
#include<cstdio> #include<algorithm> using namespace std; int N,M; struct edge { int u,v ...
- WCF探索之旅(五)——WCF与WebService的异同
前几篇文章我们简单的介绍了WCF以及怎样使用它,今天我们来讨论一下WCF和WebService的异同. 相信大多数同学跟我一样,对于WebService有所了解.并且应该说你是先听说WebServic ...
- SQLServer IP不能登录问题解决
最近项目项目需要,要在windows2008R2服务器上部署项目,可是客户那边服务器上SqlServer也没有安装,一切都要自己解决,所以我就找了个2008的版本,进行安装,安装过程没有遇到什么问题, ...
- Unity3D游戏开发最佳实践20技巧(一)
关于这些技巧这些技巧不可能适用于每一个项目. 这些是基于我的一些项目经验.项目团队的规模从3人到20人不等. 框架结构的可重用性.清晰程度是有代价的--团队的规模和项目的规模决定你要在这个上面付出多少 ...
- HDU 4445 数学-抛物运动
D - Crazy Tank ...
- Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)
D. Dima and Lisa Dima loves representing an odd num ...
- jdk、jre、spring、java ee、java se
1 java se.java ee和java me 这三个是java的标准.java se是根本,java ee建立在java se上,用于server.java me是java se的子集,用于终端 ...
- python 矩阵
python的numpy库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入numpy的包. 1.numpy的导入和使用 from numpy import *;#导入numpy的库函数 im ...
- ARM+llinux系统移植3G拨号上网收发短信(二)【转】
本文转载自:http://blog.csdn.net/hanmengaidudu/article/details/17099749 一.发送text格式的短信 给联通发text格式的短信: ~ > ...
- cmd 高级用法
1. 查看服务(service)信息 查看所有启动的服务信息: C:\Users\hasee>net start 根据启动的服务名,进一步对其启动和关闭: C:\Users\hasee>n ...