Made changes to the dynamic programming algorithms.