[kuangbin 带你飞] DP专题——HDU - 1024
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 42478 Accepted Submission(s): 15335
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.
8
Huge input, scanf and dynamic programming is recommended.
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#pragma GCC optimize(2)
//#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<sstream>
#include<iterator>
#include<cstring>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std; typedef double dou;
typedef long long ll;
#define pai acos(-1.0)
#define M 1000005
#define inf 0x3f3f3f3f
#define mod 1e18
#define left k<<1
#define right k<<1|1
#define W(a) while(a)
#define ms(a,b) memset(a,b,sizeof(a)) int n, m, ans;
int num[M], head[M], dp[M]; int main() {
ios::sync_with_stdio(false);
while (cin >> m >> n) {
ms(head, ), ms(dp, );
for (int i = ; i <= n; i++) {
cin >> num[i];
}
for (int i = ; i <= m; i++) {
ans = -inf;
for (int j = i; j <= n; j++) {
dp[j] = max(dp[j - ], head[j - ]) + num[j];
head[j - ] = ans;//此时的ans是i-1段时候的最大值
ans = max(dp[j], ans);//此时的ans是i段的时候的最大值
}
}
cout << ans << endl;
}
return ;
}
[kuangbin 带你飞] DP专题——HDU - 1024的更多相关文章
- kuangbin带你飞dp专题-基础dp
dp HDU - 1257 最少拦截系统 最长递增子序列 #include<iostream> using namespace std; const int maxn=1e7; int a ...
- 「kuangbin带你飞」专题二十 斜率DP
layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathj ...
- 「kuangbin带你飞」专题二十二 区间DP
layout: post title: 「kuangbin带你飞」专题二十二 区间DP author: "luowentaoaa" catalog: true tags: - ku ...
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- 「kuangbin带你飞」专题十七 AC自动机
layout: post title: 「kuangbin带你飞」专题十七 AC自动机 author: "luowentaoaa" catalog: true tags: - ku ...
- 「kuangbin带你飞」专题十九 矩阵
layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...
- 「kuangbin带你飞」专题十四 数论基础
layout: post title: 「kuangbin带你飞」专题十四 数论基础 author: "luowentaoaa" catalog: true tags: mathj ...
- 「kuangbin带你飞」专题十八 后缀数组
layout: post title: 「kuangbin带你飞」专题十八 后缀数组 author: "luowentaoaa" catalog: true tags: - kua ...
- 「kuangbin带你飞」专题十五 数位DP
传送门 A.CodeForces - 55D Beautiful numbers 题意 一个正整数是 漂亮数 ,当且仅当它能够被自身的各非零数字整除.我们不必与之争辩,只需计算给定范围中有多少个漂亮数 ...
随机推荐
- Springboot跨域 ajax jsonp请求
SpringBoot配置: <dependency> <groupId>org.springframework.boot</groupId> <artifac ...
- javascript中的私有作用域
我们知道js中所有的块级作用域都是无效的,块级作用域内的变量,在外部仍然可以被读取,其实是申明在外部的.如何实现变量的私有化,只在块级作用域起效,避免污染全局的变量呢.而且,挂载在全局的变量很难被回收 ...
- OpenPose 开源库安装
一.下载openpose下载openpose 使用Git直接下载openpose git clone https://github.com/CMU-Perceptual-Computing-Lab/o ...
- HDU - 5898 odd-even number (数位dp)
题意:求一个区间内,满足连续的奇数长度是偶数,连续的偶数长度是奇数的数的个数. #include<cstdio> #include<cstring> #include<c ...
- POJ 3461:Oulipo
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28155 Accepted: 11251 Descript ...
- 《百面机器学习算法工程师带你去面试》高清PDF及epub+《美团机器学习实践》PDF及思维导图
http://blog.sina.com.cn/s/blog_ecd882db0102yuek.html <百面机器学习算法工程师带你去面试>高清PDF及epub+<美团机器学习实践 ...
- C++ STD Gems03
transform.for_each #include <iostream> #include <vector> #include <string> #includ ...
- DAO三层架构及工厂模式
目录结构 1.在domain包中创建User实体类 package com.rick.domain; import java.util.Date; public class User { privat ...
- 轻量级UILabel分段点击扩展更新啦
http://www.code4app.com/thread-31445-1-1.html Tag: 项目介绍: YBAttributeTextTapAction 一行代码添加文本点击事件 效果图 S ...
- SASS - 简介
SASS – 简介 SASS – 环境搭建 SASS – 使用Sass程序 SASS – 语法 SASS – 变量 SASS- 局部文件(Partial) SASS – 混合(Mixin) SASS ...