CS373: new optimal policy algorithm