| | |
| | | |
| | | public class OptimizedLockerPacking3Utils { |
| | | |
| | | private static int signC = 0; |
| | | |
| | | public static class Item { |
| | | String name; |
| | | double unitSpace; |
| | |
| | | double targetUtilization, |
| | | List<RemainderItem> current, |
| | | List<RemainderItem> bestCombination, double[] bestDiff) { |
| | | signC++; |
| | | // 检查当前组合的有效性 |
| | | if (!current.isEmpty()) { |
| | | double diff = Math.abs(currentSpace - targetUtilization); |
| | |
| | | RemainderItem currentItem = items.get(index); |
| | | |
| | | // 不选择当前物品 |
| | | validDfsCombination(items, index + 1, currentSpace, targetUtilization, |
| | | current, bestCombination, bestDiff); |
| | | if(signC<100){ |
| | | validDfsCombination(items, index + 1, currentSpace, targetUtilization, |
| | | current, bestCombination, bestDiff); |
| | | } |
| | | |
| | | // 选择当前物品 |
| | | if (currentItem.quantity > 0) { |
| | |
| | | |
| | | for (int qty = 1; qty <= maxCanAdd; qty++) { |
| | | current.add(new RemainderItem(currentItem.item, qty)); |
| | | validDfsCombination(items, index + 1, currentSpace + qty * currentItem.item.unitSpace, |
| | | targetUtilization, current, bestCombination, bestDiff); |
| | | if(signC<100){ |
| | | validDfsCombination(items, index + 1, currentSpace + qty * currentItem.item.unitSpace, |
| | | targetUtilization, current, bestCombination, bestDiff); |
| | | } |
| | | current.remove(current.size() - 1); |
| | | } |
| | | } |