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
-1
votes
1 answer

DP for 0-1 knapsack with two factors to optimize upon. Link - http://www.spoj.com/problems/SCUBADIV/

The problem is a 0-1 Knapsack and tries to minimize the output based on 2 constraint factors. Can somebody suggest whats wrong with the following code? Its giving WA.I am using a bottom-up approach. Can somebody point out the test-cases where it…
Santosh Gupta
  • 91
  • 1
  • 8
-1
votes
2 answers

How to prove that Fractional Knapsack exhibits Greedy Strategy.?

How can i prove that Fractional Knapsack exhibits Greedy Strategy, I can do it practically but i am not able to find a method to prove it theoretically.? Please help Thanks in Advance
Anonymous
  • 19
  • 1
  • 4
-1
votes
1 answer

wrong output for memoization solution of knapsack issue

I need to solve the knapsack problem recursively, memoized and with dynamic programming. Currently I'm stuck at the memoized method (and partially the dynamic programming method). I adapted the code from what I found elsewhere on the internet.…
enenra
  • 111
  • 1
  • 11
-1
votes
1 answer

Value Independent Knapsack Problems using Dynamic Programming

I have searched all the sites. But knapsack problem is always with weights and values. I have to write algorithm and C++ implementation for the following problem.. Problem: The knapsack problem is that given a set of positive integers (a1,.....,an)…
ansariBE
  • 11
  • 3
-1
votes
3 answers

Check if numbers from multiple arrays sum up to given numbers

I was trying to do this question: Given three integers: GA, GB, and GC(which represent apples, oranges, and bananas respectively) & N lines each consisting of three integers: A, B, and C, which represent the amount of apples, oranges, and …
hell yeah
  • 17
  • 5
-1
votes
1 answer

My knapsack algorithm keeps running without returning an answer

Im trying out and algorithm i found on google books http://books.google.ee/books?id=DAorddWEgl0C&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false that solves a knapsack problem. I have built a similar one for my own project but…
Evald
  • 122
  • 10
-1
votes
1 answer

Java Genetic Algorithm to Solve the 0-1 Knapsack

Hi I need to code a Genetic Algorithm to solve the Knapsack Problem. The synopsis of the problem can be found on wikipedia, sorry for not providing the link I can currently only post 2 links. I have been able to fully understand and implement a…
user3881294
  • 1
  • 1
  • 4
-1
votes
1 answer

KnapSack Branch & Bound weird compiling errors

So I am working on implementing the KnapSack problem, using the Branch and Bound algorithm. I have finished implementing it but I am getting some weird compiling errors which I have no idea how to fix: COMPILING ERRORS gcc -Wall -pedantic -g…
Sarah
  • 313
  • 3
  • 10
-1
votes
1 answer

Work scheduling algorithm

I need an algorithm for work plan scheduling. Workers have a fix amout of time to work. They also provide information about which days(hours) they are available. The available time is higher then the workload per period. The algorithm should…
froehli
  • 904
  • 1
  • 11
  • 35
-1
votes
1 answer

Distribution Algorithm

I have a list of class Item: public class Item { public int Id { get; set; } public string Name { get; set; } public int ItemSize { get; set; } public int? ContainerId { get; set; } } and also a class Container public class Container { …
Duncan_McCloud
  • 543
  • 9
  • 24
-1
votes
2 answers

Dynamic programming Approach- Knapsack Puzzle

I'm trying to solve the Knapsack problem with the dynamical programming(DP) approach, with Python 3.x. My TA pointed us towards this code for a head start. I've tried to implement it, as below: def take_input(infile): f_open = open(infile, 'r') …
idalsin
  • 546
  • 2
  • 9
  • 31
-1
votes
1 answer

Questions about efficiency of 0/1 Knapsack?

As Knapsack has a time complexity of O(nW) for Knapsack linear time-complexity fast no matter how large W is may need a large memory when W is large if W directly proportional to n, then time complexity becomes O(n^2) none of the above which one…
-1
votes
1 answer

Knapsack Algorithm with a O(2^n*n)

Which algorithm for the knapsack problem has a O(2^n*n) complexity? I've been asked to implement a solution for the knapsack problem. I'm familiar with programming but not with asymptotic notation. Can anybody advise me on which algorithm has a…
sia
  • 401
  • 3
  • 8
  • 20
-2
votes
1 answer

Minimize the cost while reaching minimum value

Given n items with ci cost and vi value with target value X, return the number of items such that the cost is minimized while the total value of the items reaches the target X. To me, this sounds like a variation of a knapsack problem. We want to…
Nick
  • 49
  • 6
-2
votes
1 answer

0/1 Knapsack problem using Dynamic Programming, Top-Down Approach

Greeting everyone, I'm trying to solve 0/1 Knapsack problem using the Dynamic Programming Top-Down Approach. I'm pretty sure that most of my logic is correct, my code is compiling successfully. But, it's not giving the proper/correct output that is…