Dynamic programming/State reduction