Tweak the implementation a bit so that it could be turned into a top down DP solution.