1. Originally Posted by newyork
the problem doesnt allow me to change the array
and i cant "iterate through the array" because its not an itterative problem ,it a recursive problem
There are no "recursive problems", only "recursive solutions"

For each recursive step you have a count of how many items you have in your bag, plus a second array of booleans which remembers which of the items are already in the bag, plus a total of their weight.
Then you have a loop of recursive calls, to try adding each of the unused items in the bag, one at a time, adjusting count and total for each call. For each call you update a global record of the best list of items, if the total is closer than the last remembered total.
Your base cases are that you've put more items in the bag than will fit, or when all items are in the bag and your bag is still not full.

It's O(n!) but it's the only way to guarantee that you find the optimal solution. Look up the knapsack problem!

2. ## Needed more usage of this solution

If I have a list of items with different weights, and each bag can have maximum weight (let say 10), I need another code based on this code in order to find the minumum number of bags needed to fill all items.

Since I'm not a very proffesional of writting C, I appriciate a code.

My approch of solving the problem is :
Each time I find a combination fits in a bag, find all combination from the rest of items not chosen in that combination, recursively.
When there is no more items in list, save this is a set of combination.
After finding all sets, I need to find the minumum set.

3. > After finding all sets, I need to find the minumum set.
Except you don't need to record all the sets, only the smallest you found so far.
If the new one is smaller still, you keep the new one.

Oh, and bumping old threads with "please send me code" is frowned on - we're not a coding service.

4. @rabehma:

Take the total mass of the Objects divided by max per bag; this will be the best case answer on number of bags.
Note: Most of the time it is likely that the " best case answer" is not possible.

Tim S.

5. Originally Posted by stahta01
@rabehma:

Take the total mass of the Objects divided by max per bag; this will be the best case answer on number of bags.