http://acm.hdu.edu.cn/showproblem.php?pid=1024

Max Sum Plus Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45548    Accepted Submission(s): 16529

Problem 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 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. ^_^

 
Input
Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
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

Hint

Huge input, scanf and dynamic programming is recommended.

 
Author
JGShining(极光炫影)
 
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int a[];
int dp[];
int Max[]; int main()
{
int n , m;
while(~scanf("%d%d" , &n , &m))
{
for(int i = ; i <= m ; i++)
{
scanf("%d" , &a[i]);
}
memset(dp , , sizeof(dp));
memset(Max , , sizeof(Max));
int mmax ;
for(int i = ; i <= n ; i++)
{
mmax = -INF ;
for(int j = i ; j <= m ; j++)
{
dp[j] = max(dp[j - ] , Max[j - ]) + a[j];
Max[j-] = mmax ;
mmax = max(mmax , dp[j]);
}
}
cout << mmax << endl; } return ;
}

dp(最大分段和)的更多相关文章

  1. poj 2479 dp求分段最大和

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38079   Accepted: 11904 Des ...

  2. POJ-3744 Scout YYF I 概率DP

    题目链接:http://poj.org/problem?id=3744 简单的概率DP,分段处理,遇到mine特殊处理.f[i]=f[i-1]*p+f[i-2]*(1-p),i!=w+1,w为mine ...

  3. LeetCode123:Best Time to Buy and Sell Stock III

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...

  4. 2326: [HNOI2011]数学作业 - BZOJ

    首先是DP,分段DP(按位数讨论) 然后每一段构造出它对应的矩阵,用矩阵快速幂加速 type matrix=..,..]of int64; var n,m:int64; a,b,c,d:matrix; ...

  5. 【BZOJ】4565: [Haoi2016]字符合并

    4565: [Haoi2016]字符合并 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 690  Solved: 316[Submit][Status ...

  6. Codeforces Round #556 (Div. 2) - D. Three Religions(动态规划)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 3000 mSec Problem Descripti ...

  7. UOJ#110. 【APIO2015】Bali Sculptures

    印尼巴厘岛的公路上有许多的雕塑,我们来关注它的一条主干道. 在这条主干道上一共有 NN 座雕塑,为方便起见,我们把这些雕塑从 11 到 NN 连续地进行标号,其中第 ii 座雕塑的年龄是 YiYi 年 ...

  8. Java实现 蓝桥杯 算法提高 宰羊

    试题 算法提高 宰羊 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 炫炫回了内蒙,肯定要吃羊肉啦,所有他家要宰羊吃. 炫炫家有N只羊,羊圈排成一排,标号1~N.炫炫每天吃掉一只羊( ...

  9. hdu_5807_Keep In Touch(分段dp)

    题目链接:hdu_5807_Keep In Touch 题意: 在Byteland一共有nn个城市,编号依次为11到nn,同时有mm条单向道路连接着这些城市,其中第ii条道路的起点为u_iu​i​​, ...

  10. Codeforces Round #207 (Div. 1) D - Bags and Coins 构造 + bitset优化dp + 分段查找优化空间

    D - Bags and Coins 思路:我们可以这样构造,最大的那个肯定是作为以一个树根,所以我们只要找到一个序列a1 + a2 + a3 .... + ak 并且ak为 所有点中最大的那个,那么 ...

随机推荐

  1. 洛谷P4003 [国家集训队2017]无限之环 网络流 最小费用最大流

    题意简述 有一个\(n\times m\)棋盘,棋盘上每个格子上有一个水管.水管共有\(16\)种,用一个\(4\)位二进制数来表示当前水管向上.右.下.左有个接口.你可以旋转除了\((0101)_2 ...

  2. 题解 P3166 【[CQOI2014]数三角形】

    做完之后看了看题解,怎么一篇和我思路一样的也没有...我好慌啊qwq(所以一定是窝太弱了看不懂dalao的思路) 好吧窝的方法确实很奇怪: 核心代码只有3行 输入 循环 输出 一气呵成 是题解中的豪杰 ...

  3. QQ群文件未通过安全检查,禁止下载该文件

    直接用手机收藏群文件,然后用电脑登上qq去收藏里面下载就ok了

  4. LeetCode--105--从前序与中序遍历序列构造二叉树(python)

    根据一棵树的前序遍历与中序遍历构造二叉树. 注意:你可以假设树中没有重复的元素. 例如,给出 前序遍历 preorder = [3,9,20,15,7]中序遍历 inorder = [9,3,15,2 ...

  5. 进阶:python3实现 插入排序

    一图胜千言,插入排序的核心逻辑如下: 将数据分成两半,前一半是已排好序的,后一半是待排序的 每次取后一半中的第一个数,在已排序的一半中,逆序依次比较,找到要插入的位置 记录插入的位置,在最后判断是否需 ...

  6. SQL server int 转char类型

    CONVERT(CHAR,c.battery_board_id) CONVERT(VARCHAR,c.battery_board_id)

  7. leetcode打卡

    leetcode刷题打卡 刷题链接 夸夸群 刷题记录链接 期中颜色不一样的,是刷题中遇到问题的,以后需要强化 [x] 6.1 打卡 [x] 6.2 打卡 中间因个人原因没做题,后面慢慢补上 [x] 6 ...

  8. 20180829-Java多线程编程

    Java 多线程编程 Java给多线程编程提供了内置的支持.一个多线程程序包含两个或多个能并发运行的部分. 程序的每一部分都称作一个线程,并且每个线程定义了一个独立的执行路径. 多线程是多任务的一种特 ...

  9. CG-CTF | 上传绕过

    最近一直在做算法题,头都要大了,今天悄咪咪来一个web换换脑子,一发flag敲开♥[虽然知道这是个水题ε=ε=ε=┏(゜ロ゜;)┛]

  10. 前端每日实战:156# 视频演示如何用纯 CSS 创作一个飞机舷窗风格的 toggle 控件

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/jeaOrw 可交互视频 此视频是可 ...