HD 1207 (quad Hanoi)

Source: Internet
Author: User

Three algorithms for the Nottingham Tower

F (N) =2^n-1

Two ideas in a similar way

Frame algorithm

In 1941, a man named J. S. Frame in the American Journal of Mathematics, an algorithm for solving the problem of four-column Hanoi Tower is presented, which is a familiar frame algorithm:

(1) using the 4-column Hanoi algorithm, the n-r plate of the upper part of a column is moved to the B column by the C-pillar and the D-column "F (
N-r) Step ".

(2) using the 3-column Hanoi classical algorithm, the remaining r plates on column A are moved through the C-pillar to "2^r-1 step" on the D-Pillar.

(3) using the 4-column Hanoi algorithm, the n-r plate on the B-pillar is moved to "F (n-r) step" on the D-pillar by the column A and C columns.

(4) According to the above rules to find all R (1≤r≤n) in the case of step f (n), take the least worth the final solution.

So the recursive equation of the frame algorithm is as follows:

F (n) =min (2*f (n-r) +2^r-1), (1≤r≤n).

variant HanoiProblem description: On the basis of the classic Hanoi, add a condition, that is, if you add a pillar (that is, there are now four pillars a,b,c,d), calculate the n disk from the first pillar (a) to move all the required minimum number of steps on the last pillar (d), of course, can not appear large plates on the small plate. Note:1<=n<=64; analysis: Set F[n] for the minimum number of steps to be asked, obviously, when N=1, f[n]=1; when n=2, f[n]=3; like the classic Hanoi, we have three steps to finish the task of moving the PLATE: (1) x (1<=x<=n) A disk from a column to rely on the B,d column moved to the C-pillar, the process requires a step of f[x]; (2) The remaining n-x on the column B is moved to the D-pillar (note: This is not possible to rely on the C-pillar, because all the disks on the C-pillar are smaller than the disk on the A-column), That is, the steps required for this process are 2^ (n-x)-1 (Proof see again Hanoi one), (3) The X disk on the C column is moved to the D column by a b column, the process requires a step number of f[x], and the completion of the task after the completion of step (3). So the total number of steps required to complete the task f[n]=f[x]+2^ (n-x) -1+f[x]=2*f[x]+2^ (n-x)-1; But this has not met the requirements, the topic is to ask for the minimum number of steps, easy-to-know, with the different values of x, for the same n, will also come to different f[n ]。 That is, the answer to this question should be min{2*f[x]+2^ (n-x)-1}, where 1<=x<=n; in a high-level language implementation of the algorithm, we can iterate through the various values of x, and a tag variable min record x in each of the values F[n] The minimum value.

HD 1207 (quad Hanoi)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.