#K77027. Unique Paths in a Grid

    ID: 34773 Type: Default 1000ms 256MiB

Unique Paths in a Grid

Unique Paths in a Grid

You are given two positive integers m and n representing the number of rows and columns of a grid, respectively. Your task is to calculate the number of unique paths from the top-left corner to the bottom-right corner of the grid. From any cell, you can only move either right or down.

The number of ways to reach a cell (i, j) can be defined using the recurrence relation:

$$dp[i][j] = dp[i-1][j] + dp[i][j-1]$$

with the base cases:

$$dp[0][j] = 1\quad \text{for all } j, \quad dp[i][0] = 1\quad \text{for all } i.$$

Your goal is to compute $$dp[m-1][n-1]$$, the number of unique paths to reach the bottom-right corner.

inputFormat

The input is read from stdin and consists of two space-separated integers m and n, where m is the number of rows and n is the number of columns in the grid.

outputFormat

Output a single integer to stdout representing the total number of unique paths from the top-left to the bottom-right corner of the grid.

## sample
3 7
28