Skip to main content

Posts

Featured

Find the square submatrix with the highest sum of boundary elements

''' python 2.7 consider a 2D matrix of numbers from 0 to 9 with variable witdth and height. find the square submatrix with the highest sum of boundary elements. Input: input width and height of matrix : 6 8 Input matrix with numbers from 0 to 9 (get the input matrix of 8 rows and 6 columns) 2 0 6 1 2 5 1 0 5 0 1 3 3 0 1 2 4 1 0 1 3 1 1 9 4 1 0 8 5 2 0 1 0 1 2 3 6 5 3 1 0 2 0 0 1 6 0 4 input maximum width of square submatrix(for submatrix height and width are same): e.g. 3 Output: this submatrix has the highest sum of their boundry elements from matrix 2 4 1 1 1 9 => 2 + 4 + 1 + 9 + 2 + 5 + 8 + 1 => 32 8 5 2 ''' from __future__ import print_function import sys from copy import copy,deepcopy class Find_max_submatrix: def __init__(self): self.row = 0 self.column = 0 self.sub_row_col = 0 self.matrix = [[0 for col in range(sel

Latest posts

Check Power of Two

Print individual digit as words

Function Overloading in C

Quine program in python

Quine in C language