Number of Unique Paths
Given a M X N matrix with initial position at top-left cell, find the number of possible unique paths to reach the bottom right cell of the matrix from the initial position. Possible moves can be either down or right at any point in time.
Input:
The first line contains an integer T,
depicting total number of test cases.
Then following T lines contains two integers
m and n depicting the size of the grid.
Output:
Print the number of unique paths to reach
bottom-right cell from the top-left cell.
Recursion Algorithm:
So, the algorithm can be:
But this would generate many overlapping subproblems, which will be computed again and again increasing the time complexity. Hence, we can convert the recursion to dynamic Programming.
Dynamic Programming approach:
C++ Implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer