why this code will not work
int knapsack(int* arr,int* val,int n,int s){
if(n==0||s<=0)
return 0;
if(dp[n][s]>-1){
return dp[n][s];
}
int a=-1,b=-1;
if(s>=arr[n-1]){
a=val[n-1]+knapsack(arr,val,n,s-arr[n-1]);
}
b=knapsack(arr,val,n-1,s);
return dp[n][s]=max(a,b);
}
its like if i take i item then then i reduce weight but donot change size of array as i still keep it in my array to be used again
and if i don’t take it then remove it by decreasing the size n-1
similarly as we do in coin change problem to result checking all possible combinations