#K33767. Unique Paths in a Grid
Unique Paths in a Grid
Unique Paths in a Grid
Given a grid with m rows and n columns, you are required to determine the number of unique paths from the top-left corner to the bottom-right corner. You can only move either down or right at any point in time.
The number of ways can be computed using dynamic programming with the recurrence relation:
\(dp[i][j] = dp[i-1][j] + dp[i][j-1]\)
Alternatively, by combinatorics, the answer is given by the binomial coefficient:
\(\binom{m+n-2}{m-1}\)
Your task is to implement a solution that reads from standard input and writes the results to standard output for multiple test cases.
inputFormat
The first line of input contains an integer T, the number of test cases. Each test case consists of a single line containing two space-separated integers m and n, representing the number of rows and columns in the grid respectively.
outputFormat
For each test case, output a single line containing the number of unique paths from the top-left to the bottom-right corner of the grid.
## sample3
3 7
3 2
7 3
28
3
28
</p>