And we can do some optimization. We only need to look at all pallets of smaller than order weight and one smallest pallet of same or larger than order weight. No need to look at the rest of pallets of same or larger than order weight. This will reduce number of permutations to calculate. However, number of skipped permutaions should be large enough so cost of calcuting skipped permutations is more than cost of determining what pallets to take. Anyway: