Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you are attempting to list is called an <em>k</em>-multicombination. The problem is often stated this way: given <em>n indistinguishable</em> balls and <em>k</em> boxes, list all possible ways to distribute all of the balls in the boxes. The number of such distributions is:</p> <pre><code>factorial(n + k - 1) / (factorial(k - 1) * factorial(n)) </code></pre> <p>For further background, see Method 4 of the <a href="http://en.wikipedia.org/wiki/Twelvefold_way#Functions_from_N_to_X.2C_up_to_a_permutation_of_N" rel="nofollow noreferrer">Twelve-Fold Way</a>.</p> <p>Here is the code to enumerate the distributions (C++):</p> <pre><code>string &amp; ListMultisets(unsigned au4Boxes, unsigned au4Balls, string &amp; strOut = string ( ), string strBuild = string ( )) { unsigned au4; if (au4Boxes &gt; 1) for (au4 = 0; au4 &lt;= au4Balls; au4++) { stringstream ss; ss &lt;&lt; strBuild &lt;&lt; (strBuild.size() == 0 ? "" : ",") &lt;&lt; au4Balls - au4; ListMultisets (au4Boxes - 1, au4, strOut, ss.str ( )); } else { stringstream ss; ss &lt;&lt; "(" &lt;&lt; strBuild &lt;&lt; (strBuild.size() == 0 ? "" : ",") &lt;&lt; au4Balls &lt;&lt; ")\n"; strOut += ss.str ( ); } return strOut; } int main(int argc, char * []) { cout &lt;&lt; endl &lt;&lt; ListMultisets (3, 5) &lt;&lt; endl; return 0; } </code></pre> <p>Here is the output from the above program (5 balls distributed over three boxes):</p> <pre><code>(5,0,0) (4,1,0) (4,0,1) (3,2,0) (3,1,1) (3,0,2) (2,3,0) (2,2,1) (2,1,2) (2,0,3) (1,4,0) (1,3,1) (1,2,2) (1,1,3) (1,0,4) (0,5,0) (0,4,1) (0,3,2) (0,2,3) (0,1,4) (0,0,5) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload