Question

Define a generating function model for the number of ways to distribute k identical balls into...

Define a generating function model for the number of ways to distribute k identical balls into four indistinguishable boxes
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code in Python(3.x recommended)

Output:

#----------------Code-----------------

#Assumption: Any box contains at least one ball
# This is partition problem which uses this recursion to solve:
# part(n,k) = part(n-1,k-1) + part(n-k,k), where n=an integer (or balls)
# k=partitions (or boxes)
def generate(n, k):
if(n<k): # when number of balls < number of boxes, then return 0
return(0)
if(k-1==0 or k==0): # condition for recursion to end
return(1)
return(generate(n-1, k-1)+generate(n-k, k))


ball=int(input()) # number of ball
box=4
#number of ways to distribute k identical balls into four indistinguishable boxes
print(generate(ball, box))

  

Add a comment
Know the answer?
Add Answer to:
Define a generating function model for the number of ways to distribute k identical balls into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT