题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目大意: 求最大子段和,并且输出最大子段和的起始位置和终止位置. 思路: 根据最大子段和基本方法,直接在线处理(如果对最大子段和不熟悉,点这里) 需要增加两个变量,start和finish,记录最大子段和的起点和终点.如果thissum > maxsum,更新这三个值.如果thissum < 0,设置thissum = 0,并且thisstart = i + 1,因为thissum<…
2017-09-06 21:32:22 writer:pprp 可以作为一个模板 /* @theme: hdu1003 Max Sum @writer:pprp @end:21:26 @declare:连续区间最大和 @data:2017/9/6 */ #include <bits/stdc++.h> using namespace std; int main() { //freopen("in.txt","r",stdin); int cas; cin…
  A - 最大子段和 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in…
题目链接:https://vjudge.net/problem/HDU-1003 题目大意:给出一段序列,求出最大连续子序列之和,以及给出这段子序列的起点和终点. 解题思路:最长连续子序列之和问题其实有很多种求解方式,这里是用时间复杂度为O(n)的动态规划来求解. 思路很清晰,用dp数组来表示前i项的最大连续子序列之和,如果dp[i-1]>=0的话,则dp[i]加上dp[i-1]能够使dp[i]增大:若dp[i-1]<0的话,则重新以dp[i]为起点,起点更新. #include <cs…
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 193355 Accepted Submission(s): 45045 Problem Description Given a sequence a[1],a[2],a[3]--a[n], your job is to calculate the max sum of a su…
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the…
事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧! 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:…
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.   Input The first line of the input contai…
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.   Input The first line of the input contai…
Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.                       Input The first line of the…
题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义dp[i]表示以a[i]为结尾的子序列的和的最大值,因而最大连续子序列及为dp数组中的最大值.   状态转移方程:dp[1] = a[1]; //以a[1]为结尾的子序列只有a[1]:  i >= 2时, dp[i] = max( dp[i-1]+a[i],  a[i] ); dp[i-1]+a[i] > a[i]时,即dp[i-1](以a[i-1]为结尾…
https://vjudge.net/problem/HDU-1003 注意考虑如果全为负的情况,特判. 还有输出格式,最后一个输出不用再空行. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> #define lson l, m, rt<<1 #define…
解题思路:最大连续和,此题多了记录的下标,具体见代码. #include<cstdio> #include<algorithm> using namespace std; #define inf 0x3f3f3f3f int main() { , s, e, a; scanf("%d", &t); int tmp = t; while(t--) { scanf("%d", &n); s = e = k = ; sum = ,…
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4302208.html   ---by 墨染之樱花 dp是竞赛中常见的问题,也是我的弱项orz,更要多加练习.看到邝巨巨的dp专题练习第一道是Max Sum Plus Plus,所以我顺便把之前做过的hdu1003 Max Sum拿出来又做了一遍 HDU 1003 Max Sum 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目描述:…
http://acm.hdu.edu.cn/showproblem.php?pid=1003 给出一个包含n个数字的序列{a1,a2,..,ai,..,an},-1000<=ai<=1000 求最大连续子段和及其起始位置和终止位置,很基础的动态规划(DP)问题,看完DP第一次做的DP题目 DP真的是一种很优美的算法,或者说思想,但是比较难理解,我对DP的理解还很浅薄 # include <stdio.h> # define INF 1000000000 int main() { i…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29942    Accepted Submission(s): 10516 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…
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): 23844    Accepted Submission(s): 8143 Problem Description Now I think you hav…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 292444    Accepted Submission(s): 69379 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 36673    Accepted Submission(s): 13069 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" proble…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17336    Accepted Submission(s): 5701 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…
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 S 1, S 2, S 3,…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 135262    Accepted Submission(s): 31311 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s…
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 207989 Accepted Submission(s): 48681 Problem Description Given a sequence a[1],a[2],a[3]--a[n], your job is to calculate the max sum of a su…
Max Sum. The following is an instance. a)    (-2,11,-4,13,-5,-2) 思路: 最大子段和:给定一个序列(元素可正可负),找出其子序列中元素和最大的值. 1.令b[j]表示以位置 j 为终点的所有子区间中和最大的一个 2.子问题:如j为终点的最大子区间包含了位置j-1,则以j-1为终点的最大子区间必然包括在其中 3.如果b[j-1] >0, 那么显然b[j] = b[j-1] + a[j],用之前最大的一个加上a[j]即可,因为a[j]必…
传送门: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): 35988    Accepted Submission(s): 12807 Problem Description Now I think you ha…
Max Sum Plus Plus Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22262    Accepted Submission(s): 7484   Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. T…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 287192    Accepted Submission(s): 68202 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
[题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plus\) \([Hdu1024]\) \([51nod1052]\) [题目描述] 给出一个长度为 \(N\) 的序列 ,将这 \(N\) 个数划分为互不相交的 \(M\) 个子段,并使得 \(M\) 个子段的和最大. [样例] 样例输入: 7 2 -2 11 -4 13 -5 6 -2 样例输出:…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44371    Accepted Submission(s): 16084 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 21336    Accepted Submission(s): 7130 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…