天天看点

【最大子矩阵和】HDU1081-To The Max

to the max

time limit: 2000/1000 ms (java/others)    memory limit: 65536/32768 k (java/others)

total submission(s): 8193    accepted submission(s): 3981

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 rectangle. in this problem the

sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.

as an example, the maximal sub-rectangle of the array:

0 -2 -7 0

9 2 -6 2

-4 1 -4 1

-1 8 0 -2

is in the lower left corner:

9 2

-4 1

-1 8

and has a sum of 15.

input

the input consists of an n x n array of integers. the input begins with a single positive integer n on a line by itself, indicating the size of the square two-dimensional array. this is followed by n 2 integers separated by whitespace (spaces and newlines).

these are the n 2 integers of the array, presented in row-major order. that is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. n may be as large as 100. the numbers in the array will be in the range [-127,127].

output

output the sum of the maximal sub-rectangle.

sample input

4

sample output

15

source

greater new york 2001

最大子矩阵和

关于最大子矩阵和的做法探讨详细请看:http://blog.csdn.net/acmman/article/details/38580931

ac代码: