added final versions of dp code