Description Hanoi (also known as Hanoi) is a puzzle toy derived from an ancient Indian legend. When big Brahma created the world, he made three diamond pillars, and stacked 64 gold discs on a pillar from bottom to top in order of size. The great Brahma commanded the Brahman to rearrange the discs from below to the other pillars in order of size. It is also stipulated that the disc cannot be enlarged on the small disc, and only one disc can be moved between the three pillars at a time. Input number of disks n (1 <= n <=) output The process of moving a plate according to an example, each move output one line of sample input
2
Sample Output
A->ba->cb->c
HINT
Three pillars are labeled a b C, respectively.
The idea of dynamic planning, only consider the current state and the impact of the previous state, assuming that h[i-1] is the number of steps required to move the i-1 block ring, then move H[i] will need to 2*h[i]+1, the i-1 as a whole, the whole move, move to C, and then the whole moved over, to obtain the formula sum = 2^n-1. See Portal for details
022--dfs ——— Hanoi Tower Problem II by ZS learning algorithm