确定最佳组合的算法 - Bin Packing
给定一组项目,每个项目都有一个值,确定要包含在集合中的每个项目的数量,使总价值小于或等于给定限制,并且总价值尽可能大。
示例:
Product A = 4 Product B = 3 Product C = 2 Product D = 5 If Total Capacity = 10.5 , then the combination of B,C,D will be selected. If Total Capacity = 12.5 , then the combination of A,B,D will be selected. If Total Capacity = 17 , then the combination of A,B,C,D will be selected.
我正在寻找一种算法(如背包或装箱)来确定组合。任何帮助表示赞赏。
Given a set of items, each with a value, determine the number of each item to include in a collection so that the total value is less than or equal to given limit and the total value is as large as possible.
Example:
Product A = 4 Product B = 3 Product C = 2 Product D = 5 If Total Capacity = 10.5 , then the combination of B,C,D will be selected. If Total Capacity = 12.5 , then the combination of A,B,D will be selected. If Total Capacity = 17 , then the combination of A,B,C,D will be selected.
I am looking for an algorithm (like knapsack or bin packing) to determine the combination. Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说这是“像背包”。据我所知,这是有界背包问题的特殊情况,称为0-1背包问题。
它是 NP 完全的。
您可以尝试多种方法来解决该问题。请参阅此相关问题了解一种方法:
如果您只有四个项目,那么对于大多数用途来说,仅测试所有可能性就足够快了。
You say that this is "like knapsack". As far as I can see it is a special case of bounded knapsack problem called the 0-1 knapsack problem.
It is NP-complete.
There are lots of ways you could attempt to solve it. See this related question for one approach:
If you only have four items then just testing all possibilities should be fast enough for most purposes.