Doubt in DP problem Dima and Salad (CF 366C)

Revision en1, by arrrhh, 2016-08-23 14:17:04

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

rec(int tasteNow, int caloriesNow, int index) { if (tasteNow/caloriesNow) == k dptaste[index] = Math.max(dptaste[index], tasteNow) res = Math.max(rec(tasteNow+taste[index],caloriesNow+calories[index],index+1), rec(tasteNow, caloriesNow, index+1) dptaste[index] = Math.max(dptaste[index], res)

Can someone tell me what is wrong with my approach and how I can modify it to get the correct solution. Thanks

Tags #dp, newbie

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English arrrhh 2016-08-23 14:26:36 430
en2 English arrrhh 2016-08-23 14:18:05 22
en1 English arrrhh 2016-08-23 14:17:04 793 Initial revision (published)