#K66602. Unique Paths in a Grid
Unique Paths in a Grid
Unique Paths in a Grid
You are given a grid of size \(m \times n\). A robot starts at the top-left corner of the grid and can only move either right or down at any step. Your task is to calculate the number of unique paths that the robot can take to reach the bottom-right corner of the grid.
The solution involves dynamic programming where each cell represents the number of ways to reach that cell from the start. The value at cell \((i, j)\) will be the sum of the values from the cell above \((i-1, j)\) and the cell on the left \((i, j-1)\). The final answer is the value at the bottom-right cell.
Note: All formulas are provided in \(\LaTeX\) format.
inputFormat
The first line contains an integer \(T\), the number of test cases. Each of the following \(T\) lines contains two space-separated integers \(m\) and \(n\), representing the number of rows and columns of the grid respectively.
outputFormat
For each test case, output a single line containing the number of unique paths from the top-left corner to the bottom-right corner of the grid.
## sample2
3 7
4 5
28
35
</p>