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

This question already has an answer here:

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• 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
• @J.M.issomewhatokay. Thanks, also works. But AccidentalFourierTransform's answer seems faster. – becko Sep 24 '18 at 15:42
• Did you want non-negative integers or positive integers? The two suggestions in the comments are different. – Carl Woll Sep 24 '18 at 15:47