[英]Knapsack problem with values per item and limited items
I'm trying to solve a variant of knapsack problem that i haven't seen before.我正在尝试解决我以前从未见过的背包问题的变体。 in this variant we have a vector v consist of values per gram for each item and we also have a limited weight of each item and our goal is to find the maximum value that can be gain if we have a pack of size M. I tried greedy approached but haven't found any solution.
在这个变体中,我们有一个向量 v 由每个项目的每克值组成,我们每个项目的重量也有限,我们的目标是找到如果我们有一包 M 号的包可以增加的最大值。我试过了贪婪接近但还没有找到任何解决方案。 i think the most difficult part is to do it in O(n) because we shouldn't sort anything.
我认为最困难的部分是在 O(n) 中完成它,因为我们不应该对任何东西进行排序。 anyone has any idea?
任何人有任何想法?
If the value per gram has reasonably narrow bounds, you can counting-sort or radix-sort or bucket-sort it in linear time by the value per gram, and then just fill up the bucket in order of most valuable substances.如果每克的价值有相当窄的界限,您可以按每克的价值在线性时间内对它进行计数排序或基数排序或桶排序,然后按照最有价值的物质的顺序填充桶。 What do I mean by reasonable limits?
我所说的合理限度是什么意思? Specifically, I mean that there are asymptotically fewer meaningful "values per gram" than there are kinds of substances.
具体来说,我的意思是,与物质种类相比,有意义的“每克值”逐渐减少。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.