You have a stack of n boxes, with widths w., heights l\ and depths dr The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in width, height, and depth. Implement a method to build the tallest stack possible, where the heigh t of a stack is the sum of the heights of each box.
When the return value is a set of something(e.g. all the ways of arranging a chess board), DP probably is a better approach.
When the return value is a single something(e.g. the best possible way), recursion is probably a better approach.
In this case, since the return value is a single value, I used recursion.
Read full article from You have a stack of n boxes, with widths w., heights l\ and depths dr The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box
No comments:
Post a Comment