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的更多相关文章
随机推荐
- 关于jQuery写插件及其演示
关于写jQuery插件是非常有必要的.这是前端学习其中必须经过的一个过程 对于初次写插件先想清楚原理 (function($){ $.fn.yourName = function(opt ...
- java 代理模式具体解释
java 动态代理(JDK和cglib) 设计模式这东东每次看到就明确可过段时间又不能非常流利的说出来.今天就用具体的比喻和实例来加深自己的理解(小弟水平不高有不正确的地方希望大家能指出来). (1) ...
- .net Core使用Orcle官方驱动连接数据库 C#参考教程 http://www.csref.cn
.net Core使用Orcle官方驱动连接数据库 最近在研究.net Core,因为公司的项目用到的都是Oracle数据库,所以简单试一下.net Core怎样连接Oracle. Oracle官 ...
- [DevExpress]DevExpress的安装与使用
一.下载安装文件 依据自己的须要选择不同的版本号.下面为15.1 安装时选择自己须要的模块进行安装,之后进行激活,购买授权或者"其它方式". 二.安装完 在VSIDE工具栏会添加下 ...
- c#调用oracle存储过程返回数据集
c#调用oracle存储过程返回数据集 2008-12-20 10:59:57| 分类: net|字号 订阅 CREATE OR REPLACE PACKAGE pkg_tableTypeIS ...
- POJ 2977 Box walking 长方体表面两点距离
POJ2977 小学生的考试题,暴力得出O(1)的解法 #include<iostream> #include<cstdio> #include<cstdlib> ...
- jquery autocomplete自动补全
简单用法: $(function(){ var data = "the People's Republic of China".split(" "); $(&q ...
- 【149】ArcGIS Desktop 10.0 & Engine 10.0 安装及破解
写在前面:可能会出现按照此方法无法破解的情况,那请确保您有将 ArcGIS 10.0 已经完全卸载干净,直接通过控制面板进行卸载的时候并不能将其卸载干净,需要进行更深层次的卸载,包括删除注册表,各种文 ...
- Maven package打包webapp项目遇到的问题
环境Java: JDK_1.7.0_79Eclipse: Mars(4.5.0)Maven: 3.3.3最近公司同事重构某Java web项目,完成之后发现部署启动总是不成功 Caused by: o ...
- 基于CentOS7.5的 Rsync 服务详解
第1章 Rsync概述 1.1 Rsync基本概述 rsync是一款开源的备份工具,可以在不同服务器(主机)之间进行同步备份, 可实现完全备份与增量备份,因此非常适合用于架构集中式备份或异地备份等应用 ...