#C12496. Unique Paths in a Grid
Unique Paths in a Grid
Unique Paths in a Grid
Given an \(m \times n\) grid, find all unique paths from the top-left corner (0,0) to the bottom-right corner (m-1,n-1). The only allowed moves at each step are either moving down or right.
For example, in a 2x2 grid, the valid paths are:
DR RD
where 'D' represents a move down and 'R' represents a move right.
Note: The order of the paths in the output must be lexicographically sorted.
The total number of moves required to go from the top-left to the bottom-right is \(m+n-2\). In combinatorial terms, the total number of unique paths is given by the binomial coefficient \(\binom{m+n-2}{m-1}\), though an explicit computation is not required for this problem.
inputFormat
The input consists of a single line containing two space-separated integers m and n representing the number of rows and columns of the grid respectively.
Example:
3 3
outputFormat
Output all unique paths from the top-left corner to the bottom-right corner, one per line. The paths must be printed in lexicographical order.
If there is a single empty path (as in the case when \(m=1\) and \(n=1\)), output a blank line.
## sample2 2
DR
RD
</p>