Dynamic programming exercises