solve problem 164 by dynamic programming.