The rule Dijkstra uses is that the last two stretches are combined if and only if their sizes are consecutive Leonardo numbers and (in that order), which numbers are recursively defined, in a manner very similar to the Fibonacci numbers, as:
