Solving dynamic programming problems