mirror of
https://github.com/labuladong/fucking-algorithm.git
synced 2025-07-06 12:33:00 +08:00
translate pancakes sorting:
This commit is contained in:
@ -107,10 +107,10 @@ The time complexity of the algorithm is easy to calculate, because the number of
|
|||||||
|
|
||||||
Obviously, this result is not optimal (shortest). For example, a bunch of pancakes `[3,2,4,1]`. The flip sequence obtained by our algorithm is `[3,4,2,3,1,2]`, but the fastest way to flip should be ` [2,3,4] `:
|
Obviously, this result is not optimal (shortest). For example, a bunch of pancakes `[3,2,4,1]`. The flip sequence obtained by our algorithm is `[3,4,2,3,1,2]`, but the fastest way to flip should be ` [2,3,4] `:
|
||||||
|
|
||||||
* Initial state: [3,2,4,1]
|
* Initial state: `[3,2,4,1]`
|
||||||
* Turn over the first two: [2,3,4,1]
|
* Turn over the first two: `[2,3,4,1]`
|
||||||
* Turn over the first three: [4,3,2,1]
|
* Turn over the first three: `[4,3,2,1]`
|
||||||
* Turn over the first 4: [1,2,3,4]
|
* Turn over the first 4: `[1,2,3,4]`
|
||||||
|
|
||||||
If your algorithm is required to calculate the **shortest** operation sequence for sorting biscuits, how do you calculate it? In other words, what is the core idea and what algorithm skills must be used to solve the problem of finding the optimal solution?
|
If your algorithm is required to calculate the **shortest** operation sequence for sorting biscuits, how do you calculate it? In other words, what is the core idea and what algorithm skills must be used to solve the problem of finding the optimal solution?
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user