Final DP version solution of the problem
Final Dp code