Please solve this error in code
hello @vishwajeetss861999 could you please elaborate your doubt .
because you have raised the doubt in knapsack problem and your code is different .
could you please confirm in which question you have doubt ?
the given link above id for the knapsack problem
can you copy paste the code here i cant find the correction
#include
using namespace std;
int profit(int n,int c,int *wt,int pri[])
{
if(n==0||c==0)
return 0;
int ans=0;
int inc,exc;
inc =exc=0;
if (wt[n-1]<=c)
{
inc = pri[n-1]+profit (n-1,c-wt[n-1],wt,pri);
}
exc= profit (n-1,c,wt,pri);
ans= max(inc,exc);
return ans;
}
int main()
{
int wt[]={1,2,3,5};
int prices[]={40,20,30,100} ;
int n=4;
int c=7;
cout <<profit(n,c,wt,prices)<<endl;
return 0;
}