Hey Chegg I need some help solving the Knapsack problem usin

Hey Chegg I need some help solving the Knapsack problem using recursion. For those who don\'t know what the the Knapsack problem is; the Knapsack problem is, a knapsack can carry a certain amount of weight and you are suppose to figure out the possible combinations of weights that you can put in the bag based on the weights given. The first int the user inputs is the capacity of the bag and the rest of ints are all the weights. For example, if the user inputs \"20 11 8 7 6 5\" the combination should be \"8 7 5\". Anyway, I\'m having some problems getting my code to display my desired output. I need the output to look something like this if the user enters \"20 11 8 7 6 5\".

I posted my code here and go into more detail on what the output should look like.

http://pastebin.com/G2CksmkP

Solution

And in your code , I\'ve seen that you have written few mistakes

public static Listknapsack(int[] arrItems, int index, int capacity){

here you did not mention return type for the function and also object cannot be converted into list in this statement for(intk:list) . Alo, there should be spacing between list and knapsack in the statement public static list knapsack(int[] arrItems, int index, int capacity){

Please check that once . Also, please try the code below .

Hey Chegg I need some help solving the Knapsack problem using recursion. For those who don\'t know what the the Knapsack problem is; the Knapsack problem is, a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site