Given an m x n matrix A = [aij ], the objective of the problem is to find a (consecutive) submatrix of A with size at least R rows and at least C cloumns such that the average value of the numbers in the submatrix is maximized.
Let A = [aij ] be an m x n matrix. Then a p x q matrix B = [bij ] is a (consecutive) submatrix of A if there exists a fixed ordered pair (K,L) such that bij = ai+K,j+L for each (i; j) pair; note that 1<= i<= p and 1<= j<= q. For example,
The density of an m x n matrix A= [aij] is the average value of all elements of A. That is,
.Note that finding the densest submatrix of a given matrix is easy. It is just the largest element within the matrix. On the other hand, the problem becomes interesting when we are asked to find the submatrix with at least R rows and at least C columns such that the density of the submatrix is maximized.
Write a program to find the densest submatrix of A with size at least R x C.