Number of ways to reach ( M , N ) in a matrix starting from the origin without visiting ( X , Y ) | Function for computing nCr ; Function to find factorial of a number ; Function for counting the number of ways to reach ( m , n ) without visiting ( x , y ) ; Given dimensions of Matrix ; Cell not to be visited ; Function call
def nCr ( n , r ) : NEW_LINE INDENT return ( fact ( n ) // ( fact ( r ) * fact ( n - r ) ) ) NEW_LINE DEDENT def fact ( n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT res = res * i NEW_LINE DEDENT return res NEW_LINE DEDENT def countWays ( m , n , x , y ) : NEW_LINE INDENT return ( nCr ( m + n , m ) - nCr ( x + y , x ) * nCr ( m + n - x - y , m - x ) ) NEW_LINE DEDENT m = 5 NEW_LINE n = 4 NEW_LINE x = 3 NEW_LINE y = 2 NEW_LINE print ( countWays ( m , n , x , y ) ) NEW_LINE