The total number of rows is choose(n = k + n - 1, k = k - 1)
.
This function uses recursion, so is not the most efficient.
all_multinom(n, k)
Number of indistinguishable balls.
Number of distinguishable bins.
A matrix, rows index different possible multinomial counts, the columns index the bins.
n <- 5
k <- 3
all_multinom(n = n, k = k)
#> [,1] [,2] [,3]
#> [1,] 0 0 5
#> [2,] 0 1 4
#> [3,] 0 2 3
#> [4,] 0 3 2
#> [5,] 0 4 1
#> [6,] 0 5 0
#> [7,] 1 0 4
#> [8,] 1 1 3
#> [9,] 1 2 2
#> [10,] 1 3 1
#> [11,] 1 4 0
#> [12,] 2 0 3
#> [13,] 2 1 2
#> [14,] 2 2 1
#> [15,] 2 3 0
#> [16,] 3 0 2
#> [17,] 3 1 1
#> [18,] 3 2 0
#> [19,] 4 0 1
#> [20,] 4 1 0
#> [21,] 5 0 0
choose(n = n + k - 1, k = k - 1)
#> [1] 21