How Many Combinations Are Possible with Limited Repetitions?
At a glance
- 1. Set the capacities
Record the maximum number allowed from each of the n types.
- 2. Model the counts
Represent a selection by nonnegative counts whose sum is k.
- 3. Build the generating function
For each type, include one term for every allowed count.
- 4. Extract the coefficient
The coefficient of x to the power k gives the number of combinations.
Suppose you have types of items and want to select items, with order ignored. Type may be selected no more than times. The selection is determined by how many items of each type you take, so the task is to count the possible count-vectors satisfying the limits and total.
The general answer is a coefficient in a generating function. This handles different limits for different types, while a shorter inclusion-exclusion formula applies when every type has the same limit.
Model a combination as counts
Let be the number selected from type . Then a valid combination corresponds to one integer solution of
Because order does not matter, selecting two items of type A and one of type B is one combination, not three different arrangements. If each physical item is distinct, or if order matters, this count-vector model is not the right model without additional choices.
A necessary condition for any selection to exist is . If this fails, the answer is zero.
Use a generating function for arbitrary limits
For type , the allowed counts are . Encode them by the polynomial
Multiply these polynomials across all types. Choosing a term from factor records taking items of that type. The exponent in the product is the total number selected, so the coefficient of counts exactly the valid combinations:
Here means “the coefficient of in .” This is often the cleanest answer when capacities differ. For a numerical calculation, multiply the polynomials while discarding terms of degree greater than .
Worked example: four types, at most two of each
How many ways can you select five items from four types if each type may appear at most twice? The generating function is
so the answer is the coefficient of .
A direct count by the pattern of selected counts is useful as a check. The nonnegative counts must sum to 5, each at most 2. The only possible patterns are and , up to rearrangement.
For , choose which type appears once in ways, then choose which of the remaining three types is absent in ways. The other two types appear twice. This gives combinations. For , choose the type that appears twice in ways. The total is
Thus there are 16 combinations.
A formula when every type has the same limit
If all types can be chosen at most times, start with the unrestricted number of nonnegative solutions to . By stars and bars, that number is . Then use inclusion-exclusion to remove solutions in which one or more counts are at least :
A binomial coefficient term is included only for feasible indices; terms with are omitted. Each chosen set of types is shifted down by selections, which explains the reduced total inside the second binomial coefficient.
For the example above, , , and . The formula gives
No two types can both exceed the limit, since that would require at least six selections, so there are no further nonzero terms.
Common mistakes
- Using ordinary combinations without repetition: counts choosing distinct types, so it only applies when each type can be used at most once.
- Using unrestricted stars and bars: allows a type to be selected any number of times. It overcounts when there are upper limits.
- Counting arrangements instead of combinations: If order is irrelevant, do not multiply by the number of ways to arrange the selected items.
- Ignoring feasibility: If exceeds the sum of the capacities, the count is zero. If is small enough that no limit can be exceeded, the unrestricted stars-and-bars count is valid.
If each type must be selected at least once as well as at most times, replace its factor by , provided every . The coefficient method then counts selections satisfying both bounds.
References
- Enumerative Combinatorics, Volume 1, Second Edition — Richard P. Stanley
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.