Common problem in Dynamic Programming.