human
Give me a code to maximum sum submatrix and the other steps required given the following:
Maximum sum submatrix | Function to find maximum sum submatrix.
Stores the number of rows and columns in the matrix.
Stores maximum submatrix sum.
Take each row as starting row.
Take each column as the starting column.
Take each row as the ending row.
Take each column as the ending column.
Stores the sum of submatrix having topleft index ( i , j ) and bottom right index ( k , l ).
Iterate the submatrix row - wise and calculate its sum.
Update the maximum sum.
Prthe answer.
Driver Code"
Solution in Python:
assistant
#Here is code to maximum sum submatrix and the other steps required.
 def maxSubmatrixSum ( matrix ) :
	r = len ( matrix )
	c = len ( matrix [ 0 ] )
	maxSubmatrix = 0
	for i in range ( r ) :
		for j in range ( c ) :
			for k in range ( i , r ) :
				for l in range ( j , c ) :
					sumSubmatrix = 0
					for m in range ( i , k + 1 ) :
						for n in range ( j , l + 1 ) :
							sumSubmatrix += matrix [ m ] [ n ]
					maxSubmatrix = max ( maxSubmatrix , sumSubmatrix )
	print ( maxSubmatrix )
if __name__ == ' _ _ main _ _ ' :
	matrix = [ [ 0 , - 2 , - 7 , 0 ] , [ 9 , 2 , - 6 , 2 ] , [ - 4 , 1 , - 4 , 1 ] , [ - 1 , 8 , 0 , - 2 ] ]
	maxSubmatrixSum ( matrix )