PA3 Dynamic programming