I have been trying to solve this problem - 
http://www.spoj.com/problems/ABA12C/
but am getting continuous WA.
Now i have found a test case where my code gives wrong answer but am not 
able to find the fault in the logic. please help!!

The code along with the test case for which i am getting wrong answer- 
http://ideone.com/w8Ek7V

Explanation of recurrence. func(i,j,count)
It evaluates the minimum ruppees needed to buy 'i' kgs of apples from first 
'j' packets, buying exactly 'count' packets.
Following are the cases:
1- For jth packet, if the value is '-1' we skip it and go to j-1th packet 
as jth packet is not available. func(i,j,count)= func(i,j-1, count)

2- If the value of jth packet is != -1 then we can either use that packet 
or we can neglect it and go to the j-1th packet thus : func(i,j,count) = 
min{ (func(i-j, j-1, count+1), func(i,j-1, count) }

3- If the value = 0 i.e. the packet is free. then again we might either use 
it or skip it like in case of step 2. so the recurrence: func(i,j,count) = 
min{ (func(i-j, j-1, count), func(i,j-1, count) }. No count+1 here as the 
packet is free so are not going to buy it.

Hope this will help in better understanding the logic!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to