Number of ways to reach ( M , N ) in a matrix starting from the origin without visiting ( X , Y ) | C ++ program from the above approach ; 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 ) ; Driver Code ; Given Dimensions of Matrix ; Cell not to be visited ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int fact ( int n ) ; int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } int countWays ( int m , int n , int x , int y ) { return nCr ( m + n , m ) - nCr ( x + y , x ) * nCr ( m + n - x - y , m - x ) ; } int main ( ) { int m = 5 ; int n = 4 ; int x = 3 ; int y = 2 ; cout << countWays ( m , n , x , y ) ; return 0 ; }