Multi-column Tower of Hanoi problem "general solution" --c ++

Multi-column Tower of Hanoi problem

introduction

One student saw there a math problem on the Tower of Hanoi on my preliminary round Moni Juan. Probably require a minimum number of movements of the column 20 is 4.

His math is good, to find how should push.

If you want to move to another column n disks, the following steps:

  1. The plate portion (upper r a) moved to an empty column, a column movement has available 4
  2. The remaining nr a plate on the other to move empty column, available movement of the column 3 (nr a plate which can not be placed before the column was placed on a plate r)
  3. The first step of moving a r nr pillars moved over the plate, during the movement of the column there is available 4

In fact, he said, is a multi-column Tower of Hanoi Frame-Stewart algorithm of m = 4 when

Frame-Stewart algorithm

Provided that there are n disks, m pillars

The plate portion (upper r a) moves on an empty column, a column movement has available and m

The remaining nr the other moved to a plate blank columns, column movement available to the root m-1 (which can not be placed nr a plate placed on a plate of the column before r)

The first step of moving a r nr pillars moved over the plate, during the movement of the column there is available and m

Derivations

Set F. M (n) = with m columns, the minimum number of steps of movement required n disks.

then

Fm(n)=min0<r<n{2*Fm(r)+Fm-1(n-r)}

So in the end how much this r is it?

They would have to enumerate slightly ......

Code

Guess you like

Origin www.cnblogs.com/send-off-a-friend/p/11706474.html