# Using Brute Force to Solve 0-1 Knapsack

Page 1 of 1

## 1 Replies - 242 Views - Last Post: 19 February 2013 - 03:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312757&amp;s=9430302f98dbdba330d63b25afa335ab&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 MitulP91

Reputation: 1
• Posts: 64
• Joined: 18-July 12

# Using Brute Force to Solve 0-1 Knapsack

Posted 19 February 2013 - 03:26 PM

Hello all,

I've created a program that reads data off of a file and stores the variables for number of items, weight of items, value of items, and capacity of the knapsack. I am having difficulty finding a way to obtain all subsets of the items and analyzing them.

For example one of the given sets is as follows:

number of items (n) = 4
capacity (W) = 5
weight (w): 2 1 3 2
value: (v) 12 10 20 15

Thus I would need to find all subsets of {0,1,2,3} since there are 4 items. I've been looking around for a way to do this, but can not seem to figure it out myself.

If anyone could point me to a tutorial or help me in the right direction it would be much appreciated.

Is This A Good Question/Topic? 0

## Replies To: Using Brute Force to Solve 0-1 Knapsack

### #2 jimblumberg

Reputation: 4565
• Posts: 14,417
• Joined: 25-December 09

## Re: Using Brute Force to Solve 0-1 Knapsack

Posted 19 February 2013 - 03:41 PM

Duplicate topic, closed. Please stop opening new topics for the same problem.

Jim