I would calculate the optimal ways to fit the boxes inside each other.
- One Z equals one V and one X.
- One V equals two X.
- One X equals two U.
- One U equals up to five T (must be able to combine at least 2 boxes into 1 for any box merge to make sense).
This step may be rather computationally expensive depending on how many boxes you have and how easily you get fit them into each other. IE: This would be much less straightforward and harder if you had box size where they are no common multiples. See the https://en.wikipedia.org/wiki/Change-making_problem for examples of what really "nice" box size combinations would look like (the example you gave is quite nice).
Move all products in one box to other boxes with the goal of get as close to 0 remaining space as you can, ideally start by looking for moves that result in exactly 0 remaining space (only by taking everything in one box and moving it to another box).
Then merge the boxes as much as you can on the above rules as long as it reduces the # of boxes by at least one. IE: CEF=> V
(technically it would be E => F
, then EF => C
), A => X, DB => X
. Then you can combine it from there. ADB = V
(Combine 2X
boxes into a single V
box).
Another valid option is: DF => X, BCE => V, A => X
. In this case, we still combine the two X
into a V
. There are also likely solutions where you might have 1 V
and 1 Z
, but that only makes sense if you had 1X
and 1V
, otherwise it would be better to use 2X => 1V
instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…