#C1406. Unique Paths in a Grid

    ID: 43667 Type: Default 1000ms 256MiB

Unique Paths in a Grid

Unique Paths in a Grid

Given two integers m and n representing the number of rows and columns in a grid, compute all unique paths from the top-left corner to the bottom-right corner. A robot starts at the top-left corner and can only move either down (D) or right (R) at any step.

The paths should be printed in lexicographical order. If the grid is 1 x 1, the only valid path is an empty string.

The problem can be formulated mathematically as follows:

Find all sequences of moves such that
\( \begin{aligned} &\text{length} = m+n-2,\\ &\text{number of } D = m-1,\\ &\text{number of } R = n-1. \end{aligned} \)

inputFormat

The input consists of two space-separated integers m and n representing the number of rows and columns in the grid, respectively.

outputFormat

Output all unique paths, one per line, in lexicographical order. Each path is a string composed of the characters D and R. For a 1 x 1 grid, output a single empty line.

## sample
2 2
DR

RD

</p>