022--dfs ——— Hanoi Tower Problem II by ZS learning algorithm

Source: Internet
Author: User
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

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.