c# - 确定最佳组合的算法 - 装箱

标签 c# packing bin np

给定一组项目,每个项目都有一个值,确定要包含在集合中的每个项目的数量,以使总值小于或等于给定限制,并且总值尽可能大。

例子:

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.

我正在寻找一种算法(如背包或装箱)来确定组合。任何帮助表示赞赏。

最佳答案

你说这是“像背包”。据我所知,这是 bounded knapsack problem 的特例称为 0-1 背包问题。

它是 NP 完全的。

您可以尝试多种方法来解决它。有关一种方法,请参阅此相关问题:

如果您只有四个项目,那么只需测试所有可能性就可以满足大多数目的。

关于c# - 确定最佳组合的算法 - 装箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3688323/

相关文章:

c# - 如何在 SQLite-Net Extensions 中指定外键属性

r - 从 R 中的列表打包和解包元素

linux - 如何在 fish shell 中的每个 session 中永久设置 env?

c# - 具有右锚定静态面板的可变高度 FlowLayoutPanel

c# - foreach 语句不能对类型为 'System.Data.DataSet' 的变量进行操作

algorithm - 2D装箱量变化的算法

windows - 如何在 PC 上打开 Linux .bin 文件?

java - 为什么我们将 bin 目录添加到环境变量中的路径?

c# - LINQ:如何在 Any() 方法之后选择一列

git - 为什么 git 一直告诉我它是 "Auto packing the repository in background for optimum performance"?