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

Maximize the amount of money you pick up as you travel through an array

Given an array of integers for example, [1 4 3 2 9 8 7 6] Each integer represents an amount of money you can pick up. You are traveling through the array, and you can pick up the money. Every time you pick up some money, you must travel another X…
-2
votes
1 answer

Find cheapest combination of items with total value greater or equal to a target value

EDIT: I've realized my question is a variant of the knapsack problem, only instead of maximum price and weight <= target, minimum price and length >= target. I'll try figuring it out and post an answer once I do. Given an array of items, where each…
animumina
  • 11
  • 4
-2
votes
1 answer

The best and the worst case scenarios for the knapsack problem

I wonder the best and the worst case scenarios for the knapsack problem. I guess the best case should be the values and the weights for all of the objects have the same values. For example: int[] values = new int[] { 5, 5, 5}; int[] weights = new…
-2
votes
1 answer

Every time I change the constant, the result is different

I want to code the 01 Knapsack problem with c++. Each time I change the value of a constant MAX to a different value, such as 100,90, or 80, the result is different. What's the cause? I'm using Visual Studio 2019. The input is a text file, for…
-2
votes
2 answers

TypeError int and funcs

hello guys I'm trying to write code for an optimization problem in python, the problem is I need to heal a person with medicine, medicine1 heals 25 units requires 3 herb A and 2 herb B and medicine2 heals 20 units requires 4 herb A and 1 herb B.I…
vanpersie22
  • 63
  • 1
  • 1
  • 7
-2
votes
1 answer

Theoretical background of Google Or-tools

Currenlty I'm working on my thesis work about Tourism optimization, that contain both Knapsack and VRP solvers from OR-tools. At this point I need some theoretical background about OR-tools. After internet search I didn't find any information I…
-2
votes
1 answer

invalid operand to binary expression reading an array of struct

I am trying to implement the fractional knapsack famous problem. I needed a struct to connect the values and the weights. Now I want to read the array of struct item, but it gives me this: invalid expression error #include #include…
Ahmed Hossam
  • 23
  • 1
  • 6
-2
votes
2 answers

Java Knapsack: NullPointerException

When my code is trying to solve/create the greatest Knapsack (greatest Knapsack maximizes the overall total value of the Knapsack with items in it and minimizes amount of weight), I am trying to get my genetic algorithm to stop running after ten…
-2
votes
1 answer

Brute-Force Knapsack Printout

I"m using combinations to show all total subsets of items possible within a knapsack, So if I had like 10 items, with varying value and weight It'd show all combinations of the items, the total weights which is in the second spot in the tuple…
-2
votes
1 answer

Print the values of knapsack solution

I have the following solution for the knapsack problem:(wt[] is the weights array, val[] is the values array, n is the arrays size, index is the current item that we are trying (for the recursion) and arr is an array that represents weather or not…
Yinon Eliraz
  • 317
  • 1
  • 6
  • 22
-2
votes
2 answers

Fractional Knapsack

I need to implement fractional knapsack to solve this problem Value($} 20 50 10 90 110 70 60 Weight(lb) 3 4 1 5 6 3 4 but I'm getting confusing in how fractional knapsack work , I understand how the knapsack only…
stephan
  • 37
  • 8
-2
votes
1 answer

specific Knapsack Algorithm

I have problem with solve the specific knapsack algorithm problem. Is there someone who give me some tips or help me? I solved it by Brute Force method but the execute time is very long (I checked all possible combinations and take the best solution…
Zaroos77
  • 19
  • 3
-2
votes
1 answer

How can I solve it? KnapSack - values all the same but each other object has three weights

I have a problem with solve my exercise. I read about dynamic programming and algorithms and I think my exercise is "specific knapsack problem". I solved it with brute force method but I can't solve it with dynamic programming. I have a ship…
Zaroos77
  • 19
  • 3
-2
votes
1 answer

The Knapsack Max Profit

There are 4 items: A weights 2LB has profit $40, B weights 5LB has profit $30, C weights 10LB has profit $50, and D weights 5LB has profit $10. Compute the maximum total profit you can take from any of the 4 items with a knapsack weight 16LB. You…
-2
votes
1 answer

Optimum memory consumption program

Write a program to find the processes which utilize the memory optimally, given the list of the processes with their memory usage and the total memory available. Example:- Total memory :- 10 First column denotes process id's and 2nd column is the…
Zephyr
  • 1,521
  • 3
  • 22
  • 42