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 within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. I…
Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that re…
HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ans=-1e9; ;i<=n;i++){ ) tot=; tot+=a[i]; if(tot>ans) ans=tot; } return ans; } 这种做法太棒了!短短几行,就能解决最大子序列和这个问题.其实这几行代码值得深思.而且这是个在线算法,输入数据及时能给出结果,感觉不能归于动归…
To The Max Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=1081 Mean: 求N*N数字矩阵的最大子矩阵和. analyse: 乍看题目意思很简单,但对于刚开始学DP的新手来说也不是很简单. 这道题使用到的算法是:预处理+最大连续子串和 如果会做最大连续子串和,那么理解这题就相对简单一些,若不知道最大连续子串和,建议先看一下这两题: http://acm.hdu.edu.cn/showproblem.php?pi…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 250714    Accepted Submission(s): 59365 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081 To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8839    Accepted Submission(s): 4281 Problem Description Given a two-dimensional ar…
To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7620    Accepted Submission(s): 3692 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectang…
题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in th…
1.最大字段和问题 求一个序列最大连续子序列之和. 例如序列[-1,-2,-3,4,5,-6]的最大子段和为4 + 5 = 9. ①枚举法 int MaxSum(int n,int *a){ int sum = -0x3f3f3f3f; ;i<n;i++){ ; for(int j=i;j<n;j++){ b += a[j]; sum = b > sum ? b : sum; } } return sum; } ②动态规划 解题思路: 第一步:设b[ j ] 为 1到 j 的最大连续子序…
题目描述: 给定一个浮点数序列(可能有正数.0和负数),求出一个最大的连续子序列乘积. 分析:若暴力求解,需要O(n^3)时间,太低效,故使用动态规划. 设data[i]:第i个数据,dp[i]:以第i个数结尾的连续子序列最大乘积, 若题目要求的是最大连续子序列和,则易确定状态转移方程为: dp[i]=max(data[i],dp[i-1]+data[i])(dp[i]为以第i个数结尾的连续子序列最大和) 但乘积存在负负得正的问题,即原本很小的负数成了一个负数反而变大了,(负数逆袭了), 故不能…
Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j <= K.最大连续子序列是所有连续子序列中元素和最大的一个, 例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和 为20. 在今年的数据结构考卷中,要求编写程序得到最大和,现在增加一个要求,即还需要输出该 子序列的第一个和最后…
题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in th…
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 -2 -7 0 9 2 -6 2-4 1 -4 1-1 8 0 -2 处理后就是:0  -2  -9  -99   11  5   7-4 -3  -7  -6-1  7   7   5 #include <iostream> #include <stdio.h> #include &…
 To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10839    Accepted Submission(s): 5191 Problem Description Given a two-dimensional array of positive and negative integers, a sub-re…
题目链接 题意:给你一个n*n矩阵,求这个矩阵的最大子矩阵和 #include<iostream> #include<cstdio> #include<string.h> using namespace std; #define inf -0x3f3f3f3f int field[105][105],dp[105]; int main() { int n; while(~scanf("%d",&n)) { int maxn=0; memset…
传送门 题目大意: 求一个矩阵的最大子矩阵和. 题目分析: 刚开始考虑了一下dp方程的递推,但是不好转.简便的方法是预处理sum[i][j]表示第i行的前j个元素之和,之后\(n^3\)枚举子矩阵就可以了. code #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #…
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 59516    Accepted Submission(s): 27708   Problem Description Nowadays, a kind of chess game called “Super Jumping…
def MaxSum(self,array,n): sum=array[0] result=array[0] for i in range(0,n): if sum<0: sum=a[i] else: sum=sum+a[i] start1=i if sum>result: result=sum end=i start=start1 print result,start,end 上述采用的是动态规划思想:假设sum[i]表示以第i个元素结尾的最大连续字串,那么sum[i]=max{sum[i-…
题目链接:http://ac.jobdu.com/problem.php?pid=1102 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: // // 1102 最小面积子矩阵.cpp // Jobdu // // Created by PengFei_Zheng on 07/05/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <st…
LCIS                                                              Time Limit: 6000/2000 MS (Java/Others)                                                                 Memory Limit: 65536/32768 K (Java/Others)                                       …
转载于acm之家http://www.acmerblog.com/hdu-1003-Max-Sum-1258.html Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 242353    Accepted Submission(s): 57218 Problem Description Given a sequence…
第一次写博客, 自己总结写出了一道题感觉值得保存. 自己总结的规律:求最大连续子序列, 可以先求包括第N项在内的前N项最大值, (因为每一项都求过后, 前N项最大值最大的那一个元素所连续的序列即为最大连续子序列), 每次求包括第N项在内的前N项最大值时记录开始下标. 列:1 2 -2 5 -8 3: 第1项:1 开始下标为1 第2项:3 开始下标为1 第3项:1 开始下标为1 第4项:6 开始下标为1 第5项:-2 开始下标为1 第6项: 3 开始下标为6 最大值为几在于其前面项最大值是不是小于…
I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 57279    Accepted Submission(s): 22365 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师…
传送门 题目大意: 从矩阵中取出k个互不重叠的子矩阵,求最大的和. 题目分析: 对于m=1,直接最大m子段和. 对于m=2: \(dp[i][j][k]\)表示扫描到第一列i和第2列j时选取了k个矩阵的答案. 有3中转移:第一列取一段,第二列取一段,两列一起取一个宽度为2的矩阵. \[dp[i][j][k] = max(dp[i-1][j][k], dp[i][j-1][k], max\{dp[p][j][k-1]\} + s[1][i] - s[1][p], max\{dp[i][p][k-1…
Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game ca…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 154155    Accepted Submission(s): 35958 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=3415 大意是给出一个有n个数字的环状序列,让你求一个和最大的连续子序列.这个连续子序列的长度小于等于k. 由于是环状的数列,一般采取的措施是在数列的后面再复制一部分前面的数列;a[n]=a[0],a[n+1]=a[1]---- 用sum数组存储前i个数的和,那么对于j属于范围(i-k,i-1)来说,最大连续子序列就等于sum[i]减去在该范围内最小的sum[j] 那么问题就变成了求在每k个范围内最小的…
问题描述:       连续子序列最大和,其实就是求一个序列中连续的子序列中元素和最大的那个. 比如例如给定序列: { -2, 11, -4, 13, -5, -2 } 其最大连续子序列为{ 11, -4, 13 },最大和为20. =============================================================== 问题分析: 1.首先最朴素的方法是暴力 O(n^3) 直接两个for循环枚举子序列的首尾,然后再来个循环计算序列的和,每次更新和的最大值.…
C - 最大连续子序列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1231 Appoint description: Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j <= K.最大连续子…
题目链接: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…