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 – 2Cm – 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.
Here m = 5 and n = 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 moved 2 steps to the right and 4 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 – 2Cn – 1 or m + n – 2Cm – 1.
- Number of palindromic paths in a matrix
- Total number of decreasing paths in a matrix
- 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
- Paths from entry to exit in matrix and maximum path sum
- 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
- Problem of 8 Neighbours of an element in a 2-D Matrix
- Number of paths with exactly k coins
- Number of Paths of Weight W in a K-ary tree
- Printing brackets in Matrix Chain Multiplication Problem
- Paths with maximum number of 'a' from (1, 1) to (X, Y) vertically or horizontally
- Find the number of paths of length K in a directed graph
- Minimum number of steps to convert a given matrix into Diagonally Dominant Matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.