add dynamic programming solution