#C13176. Unique Paths in a Grid

    ID: 42685 Type: Default 1000ms 256MiB

Unique Paths in a Grid

Unique Paths in a Grid

Given a rectangular grid of \( m \) rows and \( n \) columns, determine the number of unique paths from the top-left corner to the bottom-right corner. You are only allowed to move either to the right or down.

The number of unique paths can be computed by dynamic programming. The recurrence relation used is:

\( dp[i][j] = dp[i-1][j] + dp[i][j-1] \), with the base conditions \( dp[i][0] = 1 \) and \( dp[0][j] = 1 \) for all valid indices.

Your task is to read the grid dimensions from the standard input, calculate the result, and print the number of unique paths to the standard output.

inputFormat

Standard Input: Two space-separated positive integers ( m ) and ( n ) representing the number of rows and columns respectively. For example, an input of "3 2" indicates a grid with 3 rows and 2 columns.

outputFormat

Standard Output: A single integer representing the number of unique paths from the top-left to the bottom-right corner of the grid.## sample

3 2
3