As in the explanation of the second test case, you can buy more than one of 
each packet.

Sent from my iPad

On 19 May 2013, at 21:44, Piyush Raman <[email protected]> wrote:

> 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 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/bb740e06-0115-488e-a710-11335f2ca0f5%40googlegroups.com?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/EB83EED2-116C-4B9D-B728-DA5622BA7EB5%40gmail.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to