# Enumerate all lists of $m$ non-negative integers that add to $n$ [duplicate]

Let $$x_1,\dots,x_m$$ be non-negative integers such that $$\sum_{i=1}^m x_i=n$$, where $$m,n$$ are given. How can I enumerate all such lists of $$m$$ integers that add to $$n$$?

Note that IntegerPartitions[n,{m}] counts two such lists as one if they are a permutation of each other, but I would count them as distinct.

Thus the list I want must have $$\binom{m+n-1}{m-1}$$ elements.

## marked as duplicate by Mr.Wizard♦Sep 24 '18 at 15:53

• Apply[Sequence]@*Permutations /@ IntegerPartitions[n, {k}] – AccidentalFourierTransform Sep 24 '18 at 15:37
• Try FrobeniusSolve[ConstantArray[1, m], n]. (I am sure this is a dupe.) – J. M. is away Sep 24 '18 at 15:38
• @AccidentalFourierTransform Thanks, that works. I didn't know that Permutations considered repeated elements as identical. Feel free to post an answer. – becko Sep 24 '18 at 15:42