Oasis Dynamic Route
A sandstorm buried the caravan map! Build a route planner that solves each smaller journey once, remembers the answer, and reveals the cheapest safe path to water.
π§ Before we start
Blossom Bloom Filter used tiny marks to remember possible membership. Today, dynamic programming remembers exact answers to repeated smaller problems, so the planner never solves the same desert route twice.
Build the remembering strategy
Arrange the visual instruction cards. Start with a tiny known answer, grow toward camp, and save each best result for later travelers.
Fill the best-cost table
Work backward from the oasis. For each stop, add the road cost to a saved future answer, then remember the cheapest total.
Reuse an overlapping answer
Two caravans arrive at Dune from different trails. The remaining Dune-to-Oasis problem is identical. Choose the efficient planner response.
Reconstruct the cheapest route
The cost table says the whole trip costs 6. Follow the saved best-next choices from Camp until the caravan reaches the Oasis.
π What you learned
- Dynamic programming splits a problem into smaller subproblems.
- A base case gives the smallest problem a known answer.
- Overlapping subproblems appear more than once, so saving their answers avoids repeated work.
- A bottom-up table solves small answers before the larger answers that depend on them.
- Each table cell compares choices and stores the best total.
- Saving the best-next choice lets a program reconstruct the winning route, not just its cost.