Dynamic programming example