Data structure learning (C ++) - recursive [2] (3)

zhaozj2021-02-16  75

1

2

3

4

5

6

Seduce

A

B

C

Obviously, the conversion of the current column is B, move the 6th plate to C. This can be obtained (regular 3): Suppose the current problem is n, after moving the nth plate to C, the problem is reduced by 1, the current column is converted to another column, the target column of the lowermost plate is C .

In summary, we have already solved this problem. It can be seen that the key is how to determine how much the current column needs to move, please ask yourself, give the following routines, because there is no optimization, I have the level of my coding The relatively low, so this function is slow - 10 times more slower than recursive.

转载请注明原文地址:https://www.9cbs.com/read-22980.html

New Post(0)