generalize dynamic programming.