ARITHMETIC WORKSHEETS

Counting an allocation with one upper bound

Count ways to place identical items into labeled boxes when one box has an upper limit, by subtracting the allocations that break the limit.

Start with no limit at all

Five identical items go into three labeled boxes, and boxes may be empty. Because the items are identical, an allocation is just a triple of counts that adds to five. The standard stars and bars argument lines up five stars and two bars, so the number of allocations is the number of ways to choose where the two bars go among seven positions. That is 7 choose 2, which the combination calculator returns as 21. The general rule for n identical items and k boxes is n plus k minus 1 choose k minus 1. Here 5 plus 3 minus 1 is 7, and k minus 1 is 2. Twenty-one is the unrestricted count, and the limit on the first box will remove some of these.

Describe the bad allocations

The limit says the first box holds at most two items. An allocation breaks it when the first box has three, four or five items. Instead of listing those, describe them with a single condition: the first box has at least three. Every allocation with that property can be built in two steps. First place three items in the first box, which uses up three of the five. Then distribute the remaining two items among all three boxes with no restriction, since the first box may take more. This one-to-one mapping between violating allocations and unrestricted allocations of the leftover items is the shift that gives the technique its name.

Counting the shifted case

After three items are committed to the first box, two identical items remain for three boxes. Stars and bars gives 2 plus 3 minus 1, which is 4, choose 2. The combination calculator gives 4 choose 2 as 6. So six allocations put at least three items in the first box. They are: (5,0,0), (4,1,0), (4,0,1), (3,2,0), (3,0,2) and (3,1,1) in the order first box, second box, third box. Writing them out is a good check on the count. Each one has first-box count at least three, and each corresponds to exactly one way of distributing two leftover items after the committed three.

Subtract once to get 15

The allowed count is the unrestricted count minus the violating count. The basic calculator gives 21 minus 6 as 15. Since every allocation either obeys the limit or breaks it, and no allocation does both, the subtraction is complete for a single bound. You can verify 15 by direct enumeration. If the first box holds 0 items, the remaining 5 go into two boxes, which has 6 options. If it holds 1, there are 4 items for two boxes, giving 5. If it holds 2, there are 3 items for two boxes, giving 4. The total is 6 plus 5 plus 4, which equals 15, matching the subtraction.

A larger example with six items

Now place six identical items in three labeled boxes with the first box holding at most three. Unrestricted, the count is 6 plus 3 minus 1, which is 8, choose 2, or 28. Violations need the first box to hold at least four, which commits four items and leaves two for all three boxes, giving 4 choose 2, or 6. The allowed count is 28 minus 6, which is 22. A direct count agrees: first box 0 gives 7 options, first box 1 gives 6, first box 2 gives 5, and first box 3 gives 4, for a total of 22. The threshold to commit is always one more than the limit, here four for a limit of three.

When more than one box is limited

This worksheet handles one upper bound. If two boxes have limits, the allocations that violate the first limit and those that violate the second can overlap, since a single allocation may break both. Subtracting both violating counts would then remove the overlap twice, and it has to be added back. That correction is the inclusion-exclusion principle. It requires counting the allocations that break both limits, which commits items to two boxes at once and may be impossible when the total is too small. For a single bound, no such overlap exists, and the clean subtraction applies.

Assumptions behind the count

The model treats items as identical and boxes as labeled, with boxes allowed to be empty unless stated otherwise. If items are distinct, each allocation of counts corresponds to many assignments, and a different formula, usually a product of choices, applies. If boxes are unlabeled, allocations that differ only by swapping boxes would be merged. The count also says nothing about which allocations are more likely. Before using stars and bars, confirm that the problem has identical items, labeled containers, an exact total and a stated bound, then translate the bound into a committed minimum for the violating case.

Why the shift works as a one-to-one map

The shifted count is valid because the mapping can be reversed. Given any violating allocation, remove three items from the first box and you obtain an allocation of the leftover two items with no restriction. Given any unrestricted allocation of two items, add three to the first box and you obtain a violating allocation. The two operations undo each other, so the sets have the same size. This is the same idea as sliding a starting point: the bound of at most two becomes a lower threshold of three, and the threshold is paid in advance. A mismatch in the mapping, such as committing only two items, would count allocations that actually satisfy the limit.

Reading the answer in context

The result 15 counts patterns of how many identical items each box receives. It does not say which items go where, since the items are indistinguishable, and it does not weight patterns by likelihood. If the five items were distinct, the same box limit would yield a different count: each item picks a box, giving 3 to the fifth power, which is 243 assignments, with those placing three or more in the first box removed by a separate sum over sizes. Stating whether the items are identical, whether boxes are labeled and whether empty boxes are allowed fixes the model, and the shift technique then applies only to the identical-item version. Boxes that must be nonempty add a second adjustment, and the usual way to handle it is to commit one item to each such box before counting.

Reproduce the checks

Unrestricted allocations

Open the Combination calculator and enter:

Total items n
7
Items selected r
2

Expected output:

Combinations

21

Empty boxes are permitted before the bound is applied.

Shifted violating allocations

Open the Combination calculator and enter:

Total items n
4
Items selected r
2

Expected output:

Combinations

6

Three items are already committed to the first box.

Allowed bounded allocations

Open the Basic calculator and enter:

First number
21
Operation
subtract
Second number
6

Expected output:

Result

15

Remove the single violating set.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Related tasks