double precision dynamic programming problem 3 ways