DP bottom-up solution, compacter code