#P3681. [CERC2016] 舞动的盘子 Dancing Disks
[CERC2016] 舞动的盘子 Dancing Disks
Description
Luka is very good at solving the Tower of Hanoi problem, and he invented a similar game that uses disks and pegs. The game has disks of different sizes and pegs. The disks are numbered from to from smallest to largest. The pegs form a grid: rows are numbered to from top to bottom, and columns are numbered to from left to right.

At the beginning, all disks are stacked on the peg at . In each move, you may choose a peg, take the top several disks, then choose some peg to its right in the same row or some peg below it in the same column, and place all the taken disks on top of that peg (their order is preserved; they are not reversed). The goal is to move all disks to , with strictly decreasing sizes from bottom to top.
Given the initial configuration, find any sequence of moves that completes the game. It is guaranteed that a solution exists.
Input Format
The first line contains a positive integer (), the number of disks.
The second line contains positive integers (), listing from bottom to top the labels of the disks on the peg at .
It is guaranteed that no two disks have the same label.
Output Format
Output lines, where is the number of moves in your solution.
In the -th line, output items , meaning that in the -th move you choose the top () disks from and move them in direction .
If you move to the right, then is R; if you move downward, then is D.
If there are multiple valid solutions, output any one.
6
1 6 5 4 3 2
1 1 D 6
2 1 D 6
3 1 D 6
4 1 D 6
5 1 D 6
6 1 R 6
6 2 R 6
6 3 R 6
6 4 R 6
6 5 R 5
6 5 R 1
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号