Dynamic Programming approach to find the best solution (general discussion)