17/40
Part 4 of 7 · A park with no cyclesLearn
The four things for the best total from the trailhead
Write the four things down for the park first.
- The cell.
best[j]is the highest total of a route fromtopto junctionj, or minus infinity when no route reachesj. - The recurrence.
best[lower]is the max, over the stretches intolower, ofbest[upper] + score. - The base case.
best[top] = 0, and every other junction starts at minus infinity, not 0. - The order. A topological order. Every stretch into a junction comes from a junction earlier in the order, so its
bestis final by the time it's read.
Minus infinity is how the table says no route. Adding a score to it leaves it at minus infinity, so it never wins a max. An exit still at minus infinity at the end can't be reached. If every exit is, the answer is None.