Questions tagged [knapsack-problem]

The knapsack problem is a problem in combinatorial optimization: Given a set of items with associated weights and values, 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 it maximizes the total value. It is an NP-complete problem, but several common simplifications are solved efficiently with dynamic programming.

There are several variants of the knapsack problem, such as 0-1 knapsack problem, bounded and unbounded knapsack problem. The unbounded and 0-1 knapsack are solved efficiently by using divide-and-conquer techniques (dynamic programming).

Other variants, where one can take a non-integer amount of an item, the weights are real numbers (and instances where other constraints become real instead of integer) are NP-complete.

A multiple knapsack problem is often referred to as the bin-packing problem.

1098 questions
-5
votes
2 answers

Please help me in solving Fractional Knapsack problem (Maximum Value of the Loot)

Maximum Value of the Loot Problem Introduction: A thief finds much more loot than his bag can fit. Help him to find the most valuable combination of items assuming that any fraction of a loot item can be put into his bag. Problem Description Task:…
Delicia Fernandes
  • 582
  • 12
  • 19
-9
votes
0 answers

Knapsack 0/1 implementation

#include int func(int index,vector &weight, vector value, int n, int maxWeight,int sum,vector> &dp,int val) { if(index==n)return val; if(dp[index][sum]!=-1)return dp[index][sum]; int…
-10
votes
1 answer

C++ Part of brute-force knapsack

reader, Well, I think I just got brainfucked a bit. I'm implementing knapsack, and I thought about I implemented brute-force algorithm like 1 or 2 times ever. So I decided to make another one. And here's what I chocked in. Let us decide W is maximum…
1 2 3
73
74