Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to print used values in knapsack problem

LolirLolir KievPosts: 1

So here we have a recursive knapsack algorithm
int knapsack(int amount,int limit, int takeWeights[], int values[]){
int used[SIZE];
int i,j,k,l,take,dontake;
if (amount == 0 || limit == 0) // stopping condition
return 0;

    if (takeWeights[amount-1] > limit) 
        return knapsack(amount-1, limit, takeWeights, values); /


    else return max(values[amount-1]+knapsack(amount-1,limit-takeWeights[amount-1],takeWeights,values)
        knapsack(amount-1,limit, takeWeights, values) );

this algorithm will return the max value of weight that can be taken.
Vut I want also to print the values it used while calculating the max value.
how can i do that?

Sign In or Register to comment.