int profitKnapsack(int *weights, int *prices, int N, int C)
{
//Base case is when bag is full or when there are no items left
if (N == 0 || C == 0)
{
return 0;
}
//Recursive Case
int profit1, profit2;
profit1 = 0;
profit2 = 0;
//Include item
if (C >= weights[N - 1])
{
profit1 = prices[N - 1] + profitKnapsack(weights, prices, N - 1, C - weights[N - 1]);
}
//Exclude item
if (C < weights[N - 1])
{
profit2 = profitKnapsack(weights, prices, N - 1, C);
}
return max(profit1, profit2);
}
I wrote this code which is slightly different from Prateek sirs code what is wrong here? I am getting 120 as answer but answer should be 140