#C8266. Unique Paths in a Grid

    ID: 52229 Type: Default 1000ms 256MiB

Unique Paths in a Grid

Unique Paths in a Grid

You are given two positive integers m and n which represent the number of rows and columns of a grid respectively. Starting from the top-left corner, your task is to compute the number of unique paths to reach the bottom-right corner of the grid. You can only move either down or right at any point in time.

The number of unique paths is given by the dynamic programming relation:

dp[i][j]=dp[i1][j]+dp[i][j1]dp[i][j] = dp[i-1][j] + dp[i][j-1]

with the base cases being that the first row and first column have only one path each.

Example: For a grid of dimensions m = 3 and n = 7, there are 28 unique paths.

inputFormat

The input consists of a single line containing two space-separated positive integers m and n representing the number of rows and columns of the grid respectively.

For example:

3 7

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.

For example:

28
## sample
3 7
28