Added dynamic programming.