I don't quite get the "if possible" clause. But here is what we can do. Have an array C[i] with counts correspondint to denominations in D[i] (ordered).
>From the lowest denomination assign 1 of each until the total doesn't exceed the required amount. Once that is done, from the highest denomination (that was assigned) to the lowest keep incrementing the count until the total doesn't exceed the required amount. On Mon, Sep 21, 2009 at 3:40 AM, Nagendra Kumar <[email protected]>wrote: > idea is to give note of each denomination at least once (if possible). > > > On Mon, Sep 21, 2009 at 10:59 AM, Shishir Mittal > <[email protected]>wrote: > >> Let the denominations be D[] = {1000,500,100}, >> and amount be N. >> Let C[] , denotes the count of each denomination. >> for ( i=0 ; i < 2 ; i++) { >> C[i] = (N-1)/D[i] ; >> N = N - D[i]*C[i] ; >> } >> C[2] = N/D[2] ; >> >> For N=4800, C[] = {4, 1, 8} >> For N= 2000, C[] = {1, 1, 5}, as required. >> >> Nice observation :) . >> >> PS: Its the Newton who appreciated the falling apple. There aren't many >> who really appreciate the happenings from our normal life. [?] >> On Sat, Sep 19, 2009 at 11:50 PM, eSKay <[email protected]>wrote: >> >>> >>> for example: if I draw 2000, what I get is >>> 1000+500+100+100+100+100+100. >>> >>> What algorithm can be used to decide how to break up the entered >>> amount? >>> >>> >>> >> >> >> -- >> Shishir Mittal >> Ph: +91 9936 180 121 >> >> >> >> > > > > -- Yesterday is History. Tomorrow is a Mystery. Today is a Gift! That is why it is called the Present :). http://sites.google.com/site/ramaswamyr --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---
<<inline: 329.gif>>
