Dynamic programming solves a problem by solving each smaller subproblem once, saving the answer in a table and reusing it.