Place n indistinguishable items into k distinguishable boxes
Roy Smith
roy at panix.com
Wed Feb 27 21:56:20 EST 2008
In article <fq56vu$aue$1 at skeeter.ucdavis.edu>,
Michael Robertson <mcrobertson at hotmail.com> wrote:
> Hi,
>
> I need a generator which produces all ways to place n indistinguishable
> items into k distinguishable boxes.
>
> For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
>
> (0,0,4)
> (0,4,0)
> (4,0,0)
>
> (0,2,2)
> (2,0,2)
> (2,2,0)
>
> (0,1,3)
> (0,3,1)
> (3,0,1)
> (3,1,0)
>
> (1,1,2)
> (1,2,1)
> (2,1,1)
>
> The generator needs to be fast and efficient.
>
> Thanks.
What course is this homework problem for?
More information about the Python-list
mailing list