hdu1003 dp(最大子段和)】的更多相关文章

题意:给出一列数,求其中的最大子段和以及该子段的开头和结尾位置. 因为刚学过DP没几天,所以还会这题,我开了一个 dp[100002][2],其中 dp[i][0] 记录以 i 为结尾的最大子段的和, dp[i][1] 记录以第 i 个数 A[i] 为结尾的和最大子段的开始位置. 对于每一个数 A[i] : 我考察它的前一个数 A[i-1] ,若以 A[i-1] 为结尾的最大子段和 dp[i-1][0] 大于等于 0 ,那么在这个基础上加上 A[i] ,一定大于等于 A[i] 本身,所以以第 i…
最近在水简单DP题,遇到了两道层层递进的DP题,于是记录一下 一.最大子段和 题意: 给出一个长度为n(n<=1e5)的序列,求连续子段的最大值 比如说2 3 -4 5 的最大值是6  而 2 3 -6 7 的最大值为7   样例输入 6 5 4 3 -15 -12 13 样例输出 13 思路一(前缀和) 因为有负数,所以前缀和的值并非单调递增的 而最大字段和只可能出现在任意两个底谷和顶峰之间 图中红色为最大子段和可能出现的地方  所以正序搜出前缀和最小值,倒序搜出最大值,对每个点获得其左边最小…
1050 循环数组最大子段和 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈,因此需要考虑a[n-1],a[n],a[1],a[2]这样的序列).当所给的整数均为负数时和为0. 例如:-2,11,-4,13,-5,-2,和最大的子段为:11,-4,13.和为20.   Input…
Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39599   Accepted: 12370 Description Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below: Your task is to calculate d(A). Input The input consists o…
描述 有 n 个小朋友排成一列.每个小朋友手上都有一个数字,这个数字可正可负.规定每个小朋友的特征值等于排在他前面(包括他本人)的小朋友中连续若干个(最少有一个)小朋友手上的数字之和的最大值.作为这些小朋友的老师,你需要给每个小朋友一个分数,分数是这样规定的:第一个小朋友的分数是他的特征值,其它小朋友的分数为排在他前面的所有小朋友中(不包括他本人),小朋友分数加上其特征值的最大值.请计算所有小朋友分数的最大值,输出时保持最大值的符号,将其绝对值对 p 取模后输出. 格式 输入格式 第一行包含两个…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1003 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; ,a[],dp[],flag=; int main() { scanf("%d",&t); while(t--) { ) pri…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 677    Accepted Submission(s): 358 Problem Description There is a number sequence A1,A2...…
#include<iostream> #include<algorithm> #include<cstdio> #define MAXN 50000 using namespace std; int n; long long a[MAXN],sum[MAXN]; /* d[j]表示以j为终点的sum中最大的. if(d[j]>0) d[j+1] = d[j]+a[j+1]; else d[j+1] = a[j+1] */ int main() { cin>&…
Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).…
To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54338   Accepted: 28752 Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located wi…