You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are n disks of different sizes and three pegs. Initially, all the disks are on the first peg in order of size, the largest on the bottom and the smallest on top. The object is to transfer all the disks to the third peg. Only one disk can be moved at a time, and it is forbidden to place a larger disk on top of a smaller one. In addition, any move should either place a disk on the middle peg or move a disk from that peg (Figure 2.19). Design an algorithm that solves the puzzle in the minimum number of moves.
There are n disks of different sizes and three pegs. Initially, all the disks are on the first peg in order of size, the largest on the bottom and the smallest on top. The object is to transfer all the disks to the third peg. Only one disk can be moved at a time, and it is forbidden to place a larger disk on top of a smaller one. In addition, any move should either place a disk on the middle peg or move a disk from that peg (Figure 2.19). Design an algorithm that solves the puzzle in the minimum number of moves.
有n個不同的小的盤子和3根柱子。最初,所有的盤子都按大小順序放置在第一根柱子上面,最大的在最下面,最小的在最上面。現在想要將所有的盤子都移動到第三根柱子上面去。一次只能移動一個盤子,而且禁止將大盤子放在小盤子上面。此外,每次移動要麽在中間柱子上面放置一個盤子,要麼從中間柱子上面取走一個盤子,如圖2.19所示,請設計一個演算法解決此問題,使得所使用的移動次數最小
用遞迴解
The text was updated successfully, but these errors were encountered: