DP bottom-up solution