Hello everyone. I was doing the problem Dima and Salad http://codeforces.me/problemset/problem/366/C and this is the recursive memoized solution that I came up with
rec(int tasteNow, int caloriesNow, int index)
so from here we can go to index+1 choosing fruit at index or index+1 without choosing fruit at index
static int rec(int tasteNow, int caloriesNow, int index) // will return maximum taste among all permissible
{
int rem = 0;
int quo = 0;
if (caloriesNow > 0){
rem = tasteNow%caloriesNow;
quo = tasteNow/caloriesNow;
}
if (rem == 0 && quo == k)
dptaste[index] = Math.max(dptaste[index], tasteNow);
if (index >= n)
return 0;
if (dptaste[index] != -1)
return dptaste[index];
int res = 0;
res = Math.max(res, Math.max(rec(tasteNow+taste[index], caloriesNow+calories[index], index+1), rec(tasteNow, caloriesNow, index+1)));
dptaste[index] = Math.max(dptaste[index], res);
return dptaste[index];
}
Can someone tell me what is wrong with my approach and how I can modify it to get the correct solution. Thanks



