The problem is to count all the possible paths from top left to bottom right of an m*n matrix with the constraints that from each cell you can either move only towards right or down.

First of all read various possible solutions for the stated problem here

Now for the last solution, the combination formula for computing number of paths is given as ** ^{m + n – 2}C_{m – 1}**. Let’s discuss the maths behind that formula.

Suppose we have an m*n matrix then according to the question we can only move right or down.

Herem = 5andn = 3, we start from(0, 0)(i.e. start) and go to the end i.e.(4, 2)we can consider any one path lets say we choose

(0, 0) -> (0, 1) -> (0, 2) -> (1, 2) -> (2, 2) -> (3, 2) -> (4, 2)

Therefore, we moved2 steps to the rightand4 steps downwards. Even if we take any other path same number of right and down steps will be required.

Now recall the combination in maths. It is just that where instead of letters we have paths. Here we have to cover n-1 + m-1 cellular length to destination.

Also recall that we are moving m-1 steps in downward direction and n-1 in right direction. Therefore the number of paths will essentially be **(m + n – 2)! / (n – 1)! * (m – 1)!** which is nothing but ** ^{m + n – 2}C_{n – 1}** or

**.**

^{m + n – 2}C_{m – 1}Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Minimum steps to convert all paths in matrix from top left to bottom right as palindromic paths
- Minimum steps to convert all paths in matrix from top left to bottom right as palindromic paths | Set 2
- Number of palindromic paths in a matrix
- Total number of decreasing paths in a matrix
- Count unique paths is a matrix whose product of elements contains odd number of divisors
- Print all possible paths from top left to bottom right of a mXn matrix
- Count all possible paths from top left to bottom right of a mXn matrix
- Print all palindromic paths from top left to bottom right in a matrix
- Print all paths from top left to bottom right in a matrix with four moves allowed
- Paths from entry to exit in matrix and maximum path sum
- Sum of cost of all paths to reach a given cell in a Matrix
- Count of palindromic plus paths in a given Matrix
- Minimum steps to convert all top left to bottom right paths in Matrix as palindrome | Set 2
- Minimize count of unique paths from top left to bottom right of a Matrix by placing K 1s
- Minimize flips required to make all shortest paths from top-left to bottom-right of a binary matrix equal to S
- Count all possible paths from top left to bottom right of a Matrix without crossing the diagonal
- Secretary Problem (A Optimal Stopping Problem)
- Transportation Problem | Set 7 ( Degeneracy in Transportation Problem )
- Reducing Equations to Simpler Form - Rational Numbers | Class 8 Maths
- Arithmetic Sequences - Sequences and Series | Class 11 Maths

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.