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.

  1. The cell. best[j] is the highest total of a route from top to junction j, or minus infinity when no route reaches j.
  2. The recurrence. best[lower] is the max, over the stretches into lower, of best[upper] + score.
  3. The base case. best[top] = 0, and every other junction starts at minus infinity, not 0.
  4. The order. A topological order. Every stretch into a junction comes from a junction earlier in the order, so its best is 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.