A few months ago I wrote a ranking of the beautiful Reading Notes of programming _ 1.3 pieces of pancakes, listing the examples in the book }, to reduce the number of searches from the original 172126 to 29, we thought that to further reduce the number of searches, we had to strengthen the pruning conditions and add a large amount of code. In fact, we only need to change one of them, the number of searches can be reduced to 11. Traverse all possible arrays and find 1st ...... The total time used for the number of 10th pancakes also dropped from 38 seconds to 21 seconds.
Changes:
1.3 _ pancake_final 148th rows
For(IntPos = 1, last_swap = cake_swap [step ++]; pos <size; ++ pos ){
Changed:
For(IntPos = size-1, last_swap = cake_swap [step ++]; pos> 0; ++ pos ){
The simple modification only changes the search order, but greatly improves the search efficiency.