Dynamic programming

Dynamic programming based on the brute-force recursive solutions.