human
Minimize count of unique paths from top left to bottom right of a Matrix by placing K 1 s | Function to return the value of Binomial Coefficient C ( n , k ).
Since C ( n , k ) = C ( n , n - k ).
Calculate the value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- -- * 1 ].
Function to find the minimum count of paths from top left to bottom right by placing K 1 s in the matrix.
Count of ways without 1 s.
Count of paths from starting poto mid point.
Count of paths from mid poto end point.
Driver Code"
Solution in Python:
assistant
#Here is code to minimize count of unique paths from top left to bottom right of a Matrix by placing K 1 s and the other steps required.
 def ncr ( n , k ) :
	res = 1
	if ( k > n - k ) :
		k = n - k
	for i in range ( k ) :
		res *= ( n - i )
		res //= ( i + 1 )
	return res
def countPath ( N , M , K ) :
	answer = 0
	if ( K >= 2 ) :
		answer = 0
	elif ( K == 0 ) :
		answer = ncr ( N + M - 2 , N - 1 )
	else :
		answer = ncr ( N + M - 2 , N - 1 )
		X = ( N - 1 ) // 2 + ( M - 1 ) // 2
		Y = ( N - 1 ) // 2
		midCount = ncr ( X , Y )
		X = ( ( N - 1 ) - ( N - 1 ) // 2 ) +
			( ( M - 1 ) - ( M - 1 ) // 2 )
		Y = ( ( N - 1 ) - ( N - 1 ) // 2 )
		midCount *= ncr ( X , Y )
		answer -= midCount
	return answer
if __name__ == ' _ _ main _ _ ' :
	N = 3
	M = 3
	K = 1
	print ( countPath ( N , M , K ) )