#C2481. Unique Paths in a Grid
Unique Paths in a Grid
Unique Paths in a Grid
Given a grid of width w and height h, your task is to determine the number of unique paths from the top-left corner to the bottom-right corner. You can only move either right or down at any point in time.
The solution can be derived using dynamic programming. If we define dp[i][j] as the number of ways to reach cell (i, j), then the recurrence relation is:
$$ dp[i][j] = dp[i-1][j] + dp[i][j-1] $$
with the base cases being dp[i][0] = 1 for all i and dp[0][j] = 1 for all j since there is only one way to reach any cell in the first row or column.
For example, a 2x2 grid has 2 unique paths, and a 3x3 grid has 6 unique paths.
inputFormat
The input consists of two space-separated positive integers w and h representing the width and height of the grid, respectively.
outputFormat
Output a single integer representing the number of unique paths from the top-left corner to the bottom-right corner of the grid.
## sample2 2
2