Max Sum Plus Plus——A
A. Max Sum Plus Plus
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
Process to the end of file.
Output
Sample Input
1 3 1 2 3
2 6 -1 4 -2 3 -2 3 (子段1: 4;子段2:3 -2 3)
Sample Output
6
8
Hint
#include <iostream>
#include<cmath>
#include<cstring>
using namespace std;
const int MAX=;
const int INF=0x7fffffff;
int a[MAX];
int b[MAX];
int c[MAX];
int main()
{
int m,n;
while(cin>>n>>m)
{
for(int i=;i<=m;i++)
cin>>a[i];
memset(b,,sizeof(b));
memset(c,,sizeof(c));
int maxn;
for(int i=;i<=n;i++)
{
maxn=(-)*INF;
for(int j=i;j<=m;j++)
{
b[j]=max(b[j-]+a[j],c[j-]+a[j]);
c[j-]=maxn;
if(b[j]>maxn)
maxn=b[j];
}
}
cout<<maxn<<endl;
}
return ;
}
Max Sum Plus Plus——A的更多相关文章
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- 2016huasacm暑假集训训练五 J - Max Sum
题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/J 题意:求一段子的连续最大和,只要每个数都大于0 那么就会一直增加,所以只要和0 ...
- Max Sum
Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...
- HDU 1024 max sum plus
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- hdu 1024 Max Sum Plus Plus
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
- hdu 1003 Max sum(简单DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- HDU 1003 Max Sum
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- Leetcode: Max Sum of Rectangle No Larger Than K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
随机推荐
- thinkphp分页样式
html代码: <div class="pages">{$page}</div> css代码: .pages{ width:100.5%; text-ali ...
- PHPCMS V9 栏目列表调用文章点击量及评论数量方法
很多朋友在用Phpcms做站时,具体需要在列表页.首页调用文章列表调用文章的点击量和评论排行,那么怎么才能做到在Phpcms v9首页.频道页.列表页.推荐位等页面获取文章浏览量和评论统计呢? 原因起 ...
- [Oracle] PL/SQL学习笔记
-- 1. 使用一个变量 declare -- Local variables here v_name ); begin -- Test statements here select t.user_n ...
- VR 相关专业词汇
最近在看 SIGGRAPH2015 有关 VR Display and Interaction 的几篇文章,之前从来没看过有关方面的 paper,一看才发现专业词汇太多了,根本不懂啊,幸亏 Paper ...
- [Liferay6.2]启动Tomcat提示APR不能在java类库路径中被找到的解决办法
问题描述 启动liferay之后,在控制台中打印出会打印出以下信息: 信息: The APR based Apache Tomcat Native library which allows optim ...
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- Vue入门笔记#过渡
Vue过渡,可以在元素从DOM中移除,插入时自动调用过渡效果.根据设定,会适时的触发过渡效果. 在使用的目标标签里添加 transition: <div transition="my_ ...
- 587A
#include<iostream> #include<algorithm> #include<stdio.h> #include<stdlib.h> ...
- Oracle注入漏洞
sqlmap.py -u "http://10.7.82.123:9104/servlet/json" --cookie="JSESSIONID=abcgk26KDf_5 ...
- hdu 5692 Snacks 线段树+dfs
Snacks Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...