Practicing Dynamic programming