human
Minimum operations required to set all elements of binary matrix | Return minimum operation required to make all 1 s ..
check if this cell equals 0.
increase the number of moves.
flip from this cell to the start point.
flip the cell.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum operations required to set all elements of binary matrix and the other steps required.
 def minOperation ( arr ) :
	ans = 0
	for i in range ( N - 1 , - 1 , - 1 ) :
		for j in range ( M - 1 , - 1 , - 1 ) :
			if ( arr [ i ] [ j ] == 0 ) :
				ans += 1
				for k in range ( i + 1 ) :
					for h in range ( j + 1 ) :
						if ( arr [ k ] [ h ] == 1 ) :
							arr [ k ] [ h ] = 0
						else :
							arr [ k ] [ h ] = 1
	return ans
mat = [ [ 0 , 0 , 1 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] ]
M = 5
N = 5
print ( minOperation ( mat ) )