0

Is there a way to count the number of permutations of $n$ non-negative integers $[X_1,\ldots, X_n]$ (i.e., order matters) with $\sum_{i=1}^nX_i\leq M$ for a positive $M$ and $X_i\leq m_i$ for $n$ positive $m_i$'s?

If $m_i$'s are equally $m$, the problem would be reduced to find the numbers of permutations satisfying $\sum_iX_i=k$ with $X_i\leq m,\forall i$, $k=0,1,\ldots,M$, respectively, and then adds the numbers together. For each individual $k$, the question has been answered, using stars-and-bars and inclusion-exclusion. For example: How many ways can $b$ balls be distributed in $c$ containers with no more than $n$ balls in any given container?

However, what if $m_i$'s in the constraints can be different?

leeyee
  • 317

1 Answers1

1

Use the principle of inclusion exclusion. First ignore the restrictions $X_i\le m_i$, and count the number of lists $[X_1,\dots,X_n]$ with $\sum_i X_i=m$. Using stars and bars, this can be shown to be $\binom{n+m}{n}$. Then, for each variable $X_i$, subtract the bad lists where $X_i\ge m_i+1$. This is equivalent to counting nonnegative lists $$ [X_1,\dots,X_{i-1},X_{i}-m_{i}-1,X_{i+1},\dots,X_n] $$ whose sum is $m-m_i-1$. The number of such lists is $\binom{n+m-m_i-1}n$. However, now the lists with two entries which are too big have been doubly subtracted, so these must be added back in. And so on. The answer ends up being $$ \sum_{S\subseteq \{1,2,\dots,n\}}(-1)^{|S|}\binom{n+m-\sum_{i\in S}(m_i+1)}{n}. $$ Note that this formula only works if you adopt the convention that when $r$ is negative, $\binom{r}k=0$.

Mike Earnest
  • 75,930