How to Search a Database of Package Deals for Specific Items with the Fewest Unwanted Extra Items
I don't think anyone has come up with a complete answer for your question. This sounds like a complex math question which does not belong on the "Database Administrators" site.

With that said, Joe Celko has an article that might help you. Bin Packing Problems: The SQL