Analysis of N-tower problems.

Source: Internet
Author: User

First, let's talk about the Three Towers.

The recursive formula is f (n) = 2f (n-1) + 1.

First, let's talk about how this formula was introduced.

 

We need to move all the plates on the first tower to the last one.

Suppose there are n plates.

Then, we need to first move n-1 dishes to the second tower,

Then, move the largest plate to the 3rd towers.

Finally, move n-1 plates to the third tower.

 

Therefore, F (n) = f (n-1) + 1 + f (n-1) is obtained)

That is, the formula F (n) = 2f (n-1) + 1.

 

 

Four-tower problem: (this method has a problem. It will be wrong at 10. Please give me some advice !)

According to some derivation, the following conclusions are drawn:

 

/F (n) = 1 n = 1

| F (n) = 3 N = 2

| F (n) = 2f (n-2) + 3 n = 3

/F (n) = 2f (n-3) + 7 N> = 4

 

Why is n> = 4?

To get the minimum number of moves, we just need to move the previous n-3 plate to the auxiliary Tower first.

Then move the last three plates to the last tower based on the three towers. (Because one of the towers has been occupied by n-3 plates)

Finally move the n-3 plate to the last tower.

So F (n) = f (n-3) + 7 + f (n-3)

7 is the number of times the three towers need to be moved.

 

Five, six, and seven ...... And so on...

The N-tower problem has also been solved perfectly.

 

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.