0
$\begingroup$

I have $K$ variables.

Each variable can take any value form a set with $N$ elements.

We have $N^K$ possible solutions (permutations with repetition, when at each time slot we can choose among $N$ elements each time). However, some of these $N^K$ possible solutions will provide the same offered rate (we do not care about the ordering). So, the possible solutions reduce to:

$\frac{(K+N-1)!}{K!(N-1)!}$

How can I generate all these possible combinations when $N=7$, $K=20$?

$\endgroup$
  • $\begingroup$ Can you please illustrate the desired combinations with a few small examples? $\endgroup$ – Kiro May 3 at 9:30
  • $\begingroup$ @Kiro, please see my edit. $\endgroup$ – dipak narayanan May 3 at 9:38
1
$\begingroup$
With[{n = 2, k = 3},
  Join @@ Table[IntegerPartitions[s, {k}, Range[n]], {s, k, n k}]]

{{1, 1, 1}, {2, 1, 1}, {2, 2, 1}, {2, 2, 2}}

With[{n = 7, k = 20},
  Join @@ Table[IntegerPartitions[s, {k}, Range[n]], {s, k, n k}]]

{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, ..., {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6}, {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}}

(230230 solutions)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.