How to Distribute Identical Stones Among Buckets with Limits
At a glance
- 1. Clarify the objects
Decide whether the stones are identical and whether the buckets are distinct.
- 2. Set the bounds
Represent the number in bucket i by x_i, with a lower limit L_i and upper limit U_i.
- 3. Subtract minimums
Set aside the required minimum in every bucket, then count the remaining stones.
- 4. Apply the cap
Use inclusion-exclusion or a generating function to enforce each bucket’s maximum.
- 5. Check the interpretation
If stones or buckets are distinguishable, use a different counting rule.
“Distribute stones into buckets with limits” can mean several different counting problems. The standard interpretation is that the stones are identical, the buckets are distinct, and each bucket has a minimum and maximum number of stones. Under that interpretation, each distribution is an integer solution to a system of bounded equations.
If the stones are distinct, or if swapping buckets does not create a new distribution, the count changes. The methods below state which assumptions they use and explain those alternatives.
Model the distribution
Suppose there are distinct buckets and identical stones. Assume the bounds are integers with . Let be the number of stones placed in bucket . If bucket must hold at least and at most stones, the problem is to count solutions of
First check feasibility: the total must satisfy . If not, there are no valid distributions.
When there are only lower bounds, subtract them: set . The new variables are nonnegative and sum to . With no upper bounds, the stars-and-bars count is . Upper bounds require an additional step.
Count with upper limits
After subtracting the minimums, define the capacity . The remaining variables satisfy and sum to . Inclusion-exclusion starts with all nonnegative solutions, then removes solutions that exceed one or more capacities:
Treat a binomial coefficient as zero if its top argument is less than . For each selected bucket in , the formula subtracts from its count, representing the amount by which that bucket exceeds its limit. Inclusion-exclusion corrects for solutions that violate multiple limits.
A compact equivalent is the generating-function coefficient
Here means “the coefficient of .” Choosing a term from bucket records putting of the remaining stones there; the product counts every allowed choice whose total exponent is .
Worked example
How many ways can 10 identical stones be placed in 4 distinct buckets if each bucket must contain between 1 and 4 stones?
Subtract one stone from each bucket. That leaves stones to distribute, and each bucket can receive at most additional stones. Without the upper limits, stars and bars gives
Now remove distributions in which some bucket gets at least 4 of the remaining stones. For a specified bucket, subtract 4 from its count; the other counts then sum to 2. There are such distributions for that bucket, and there are 4 choices of bucket. Two buckets cannot each exceed the cap because that would require at least 8 of the 6 remaining stones. Therefore the answer is
There are 44 valid distributions. For example, the bucket counts are valid; is also valid, while violates a maximum.
A practical procedure
- Decide whether stones and buckets are distinguishable.
- Write one variable for each distinct bucket and record its minimum and maximum.
- Subtract each minimum and calculate the remaining total and capacities .
- Check that .
- Use inclusion-exclusion for a formula, or take the coefficient of in the generating function.
For a small problem, you can also multiply the short polynomials directly or list feasible values of all but one variable. The final variable is then forced by the required total.
Common mistakes
- Treating buckets as interchangeable. With distinct buckets, and are different distributions. If buckets are identical and have the same constraints, they are not counted separately, and the problem becomes a count of unordered group sizes.
- Using stars and bars without enforcing caps. The formula allows a bucket to exceed its maximum. Use it alone only when there are no upper bounds, or when no unrestricted solution can exceed any cap.
- Forgetting to shift the total. After placing the required minimums, count , not the original .
- Assuming distinct stones follow the same count. If stones are distinct and bucket must receive stones, that count vector corresponds to assignments. Sum this quantity over all valid count vectors.
If the stones are identical but the buckets are indistinguishable and have the same bounds, a useful starting point is to count nondecreasing or nonincreasing lists of bucket sizes satisfying the bounds. That is a different problem from ordinary stars and bars because permutations of bucket counts no longer represent separate outcomes.
References
- Concrete Mathematics: A Foundation for Computer Science, Ronald L. Graham, Donald E. Knuth, and Oren Patashnik
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.