假设我有一个包含 100 种产品的 list ,每一种都有一个价格。每个也有一个能量 (kJ) 测量值。
是否有可能使用编程找到 15 种产品的最佳组合,其中能量总和 (kJ) 最大,价格低于 10 美元?
我知道 C#,但任何语言都可以。干杯。
更新:在寻找背包问题的示例源代码时遇到了一些麻烦。有没有人有或知道在哪里可以找到一些。在谷歌上搜索了几个小时,如果可能的话,需要在明天之前解决这个问题。塔。
最佳答案
http://en.wikipedia.org/wiki/Knapsack_problem
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items...
关于寻找最佳组合的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/680524/