#C12168. Unique Paths in a Grid
Unique Paths in a Grid
Unique Paths in a Grid
You are given an m x n grid. A robot starts at the top-left corner of the grid and wants to reach the bottom-right corner. The robot can only move either down or right at any point in time. Your task is to calculate the number of unique paths that the robot can take to get from the start to the destination.
This problem can be solved using dynamic programming. Consider the recurrence relation:
\( dp[i][j] = dp[i-1][j] + dp[i][j-1] \)
with the base cases \( dp[i][0] = 1 \) for all \( i \) and \( dp[0][j] = 1 \) for all \( j \). The value at \( dp[m-1][n-1] \) gives the total number of unique paths from the start to the destination.
Note: The input will contain two positive integers representing the dimensions of the grid.
inputFormat
The first line of the input contains two space-separated integers m
and n
, representing the number of rows and columns of the grid respectively.
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.
## sample3 7
28
</p>