A more advanced adaptation of a Dynamic Programming problem