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-...
3
votes
2answers
55 views
2
votes
1answer
44 views
0-1 Knapsack problem - implementation
Given a set of items with a weight and a value, this problem gives the subset of items which maximize value so that their combined weights is less or equal than a given maximum weight. This solution ...
3
votes
2answers
157 views
3
votes
1answer
80 views
Code for dividing gifts equally
I recently came across this problem:
It is Lavanya's birthday and several families have been invited for
the birthday party. As is customary, all of them have brought gifts
for Lavanya as well ...
3
votes
3answers
216 views
Fractional Knapack as asked in an interview
Description:
Given the Knapsack capacity and the weight and value of some items,
find a way to maximize the value in the given Knapsack.
Code:
...
3
votes
2answers
146 views
Change-making problem with specific constraints
I am a new Pythoner. I have solved a OJ project with Python. Can you tell me how can I solve it more Pythonically?
Problem Description: There are n coin denominations, each with an unlimited ...
5
votes
1answer
70 views
Stampcalculator - Given a set of stamps, what combinations are there to reach a certain amount?
Background
My mother has a hobby of buying and reselling books via online trading sites. After a price is agreed on, the books have to be put into an envelope for mailing. On this envelope, stamps ...
2
votes
0answers
46 views
Unbounded knapsack solution with items of equal value
My solution correctly solves the problem, but I would like to optimize its performance. For a capacity of 7 and bars = [ 4, 1, 1, 2, 1], the output is 7.
...
3
votes
1answer
146 views
Knapsack algorithm in JavaScript - Integer weights and values
My version of Knapsack works only when the weights or values of items are whole numbers.
Restrictions
You are given an array of objects each of which contains a weight and value.
You are also given ...
2
votes
1answer
91 views
Fractional Knapsack
This is my solution to an assignment on the fractional Knapsack problem. I take as problem input the following pieces of information:
The number of item types
The total weight limit
For each item ...
6
votes
1answer
255 views
Python Knapsack problem: greedy
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for ...
1
vote
1answer
335 views
Knapsack 01 solution
Solution to bounded knapsack 01 problem. Once again comprehensive description is difficult in this space, refer here. Looking for code review. optimizations and best practices.
...