Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 确定最佳组合的算法-装箱_C#_Packing_Bin_Np - Fatal编程技术网

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

C# 确定最佳组合的算法-装箱,c#,packing,bin,np,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 w

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

例如:

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. 产品A=4 产品B=3 产品C=2 产品D=5 如果总容量=10.5,则选择B、C、D的组合。 如果总容量=12.5,则将选择A、B、D的组合。 如果总容量=17,则将选择A、B、C、D的组合。 我正在寻找一个算法(如背包或箱子包装)来确定组合。感谢您的帮助。

您说这是“像背包一样”。据我所知,这是一个叫做0-1背包问题的特例

它是NP完全的

有很多方法可以尝试解决它。关于一种方法,请参见此相关问题:


如果你只有四个项目,那么就大多数目的而言,测试所有可能性应该足够快。

这个问题的背景是什么?这是你需要解决的实际问题吗?是作业吗?我不是学生。这是为了找到产品固定折扣的最佳组合。购物车应该自动从给定的折扣(产品的合格折扣)中找到折扣的最高值。例如:如果产品价格为30美元,并且有资格享受5美元、10美元和50美元的折扣,购物车应选择5美元和10美元。我已经用组合数论把算法组合起来了。我正在为这个场景寻找更多的技巧或算法。谢谢你的帮助。