AlgoViz

Min Cost Climbing Stairs

easy 16 min

Each step has a toll; you may start on step 0 or 1, pay for every step you stand on, and climb one or two at a time.

Where it shows up

The same pattern appears across everyday software.

  • Shortest paths in a DAG

    The staircase is a tiny directed acyclic graph: each step links to the next two. Route planners, build systems and project schedulers solve the same kind of problem on larger DAGs by relaxing nodes in order, exactly like filling dp left to right.

  • Toll and fuel planning

    Choosing which stops to make along a fixed road, where each stop has a price and you can only drive so far between stops, is this recurrence with a wider window. Fuel-stop planners for trucks and long drives use it.

  • Line breaking in text layout

    TeX's Knuth-Plass algorithm picks where to break lines by giving each break a badness cost and choosing, for each position, the cheapest earlier break. It is a 1D "cheapest way in" DP followed by walking back to read off the breaks.

  • Viterbi decoding

    Speech recognition, error-correcting codes and gene finding use the Viterbi algorithm: keep the best score into each state at each position, then backtrack from the end. That is cost plus the best predecessor, then path reconstruction, at a larger scale.

  • Game level checks

    Platformer designers verify that a level is beatable within an energy or time budget by computing the cheapest sequence of short and long jumps across platforms, the same 1-or-2 move model with a cost per landing spot.