简体   繁体   English

每件物品价值和有限物品的背包问题

[英]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.

相关问题 物品的重量取决于所选物品的背包问题 - Knapsack problem with item's weight depending on items selected 背包问题 - 从 5 组中选择最佳可能的项目组合,包括每组 1 项 - Knapsack problem - selecting best possible combination of items from 5 sets including 1 item from each set 如何在背包问题中获取背包中物品的名称 - How do i get the name of items in knapsack in knapsack-problem 01 限制m件的背包问题 - 01 knapsack problem with the limit of m items 0-1 物品数量有限制的背包问题 - 0-1 Knapsack problem with bound in the number of items 0/1 背包问题 - 需要浮点/双值的解决方案 - 0/1 Knapsack problem - Need solution for float/double values 如何从背包问题的 DP 表中导出最大数量的项目? - How to derive max amount of items from DP table of Knapsack problem? 解决背包的变体,其中物品的价值取决于麻袋中已有的物品 - Solving a variation of the knapsack in which the value of an item depends on items that are already in the sack 如何知道在背包问题中选择了哪个项目(DP实施)? - How to know which item was selected in the knapsack problem(DP implementation)? 没有价值的背包或类似物,以及可以分配哪些物品的限制? - Knapsack or similar with no values and with limits as to which items can be assigned where?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM