Dynamic programming to optimize treatment and replacement decisions.