Solving Dynamic Programming Problems using java