Break a hard problem into overlapping subproblems, solve each one only once, and store the answer. Exponential work collapses into polynomial.
Dynamic programming (DP) is not a data structure — it is a technique. It applies when a problem has two traits: overlapping subproblems (the same smaller problem is solved again and again) and optimal substructure (the best overall answer is built from the best answers to its parts). The fix is simple: solve each subproblem once, store the result in a table, and reuse it. You can work top-down (recursion plus a cache — memoization) or bottom-up (fill a table from the smallest pieces — tabulation). Either way, exponential recomputation becomes a single pass.
Each tower is a grid cell. The goal: cheapest path from the back corner to the front, moving only right or forward. Each cell's height becomes its cost + the cheaper of its two solved neighbors.
If a problem has both pillars, DP applies — and you can implement it top-down or bottom-up.
For this grid problem (n cells per side), DP turns exponential recursion into a clean quadratic fill.