I need to write C++ to solve 0/1 knapsack problem by greedy algorithm. Because it is a NP complete problem so we can only find the nearest solution.I have already finished it by ratio(value/weight), but dont know how to turn Benefit focus only(choose one by one only by value) to code.
Asked
Active
Viewed 504 times
-3
1 Answers
0
Greedy method for Benefit only denotes that you get items with the largest value until weight sum reaches knapsack capacity.
So just sort items by value and sum both values and weights in parallel.
Note that this problem is simpler than one with B/W ratio

MBo
- 77,366
- 5
- 53
- 86