[Math] Distribute $N$ objects to $K$ boxes such that no box has more than $X$ and not less than $Y$ objects.

combinationscombinatorics

I have $N$ indistinguishable objects and $K$ distinguishable boxes and I need to calculate ways how i can put this objects to boxes that no box has more than $X$ and not less than $Y$ objects.

I found topic How many ways to distribute $n$ objects into $r$ boxes so that each box have at least $1$ (but no more than $k$) objects? with recurrent formula but it's too slow and takes too much time with not little numbers.

Is there another way to calculate it?

Best Answer

Notice that what you want eventually reduces to distributing $N-((K-1)X) $ balls over $K $ boxes, with no box having more than $Y-X+1 $ balls, so it is reduced to the same problem you linked.

Distributing $N $ balls over $K $ boxes with a minimum of 1 ball and a maximum of $M $ is the same as distributing $N-M $ balls over $K $ boxes with each box having, at most, $M-1$ balls.

This means your problem is equivalent to distributing $N-(KX) $ balls over $K $ boxes with no box having more than $Y-X $ balls.

If you find a better solution to that problem then you find a better solution for yours.

I guess you could use the Principle of Inclusion-Exclusion to impose your restrictions but it is also not a closed formula. And although you can make it non-recursive, it is recursive in nature.