#C288. Unique Paths in a Grid
Unique Paths in a Grid
Unique Paths in a Grid
You are given a grid with dimensions m x n. Starting from the top-left corner (0, 0), you need to reach the bottom-right corner (m-1, n-1) by only moving either down or right at any point in time.
The number of unique paths can be calculated using dynamic programming. Specifically, let \(dp[i][j]\) represent the number of ways to reach the cell at row \(i\) and column \(j\). The recurrence relation is:
\[ dp[i][j] = dp[i-1][j] + dp[i][j-1] \]
with the base conditions \(dp[i][0] = 1\) for all \(i\) and \(dp[0][j] = 1\) for all \(j\). Your task is to compute \(dp[m-1][n-1]\), which is the total number of unique paths from the top-left to the bottom-right corner.
inputFormat
A single line containing two space-separated integers m and n.
outputFormat
Output a single integer which is the number of unique paths from the top-left corner to the bottom-right corner of the grid.## sample
3 7
28
</p>