简体   繁体   中英

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. i think the most difficult part is to do it in O(n) because we shouldn't sort anything. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM