2
$\begingroup$

My math skills are a bit rusty, I've run into this problem which is I'm sure a classic variation of combinatorics (please name it if so).

Given a set of N items to choose from, choose R (nCr), but there are a fixed number of repetitions allowed and then no more. For instance, 6 items (a,b,c,d,e,f), choose 6, 2 repeats allowed:

valid answers:

a,a,b,b,c,d
a,a,a,b,b,c
a,b,a,b,a,c   [edit: repeats don't have to be contiguous]
a,a,a,c,b,b   [edit: repeats don't have to be adjacent to each other]

invalid:

a,a,b,b,c,c

not sure (zero or one repeat may be allowed, but I don't know yet):

a,b,c,d,e,f
a,a,a,a,a,a
a,a,a,a,b,c
$\endgroup$
1
  • $\begingroup$ You should try to improve the wording of your question: I don't think this is what most people would call the number of repetitions. $\endgroup$ Commented Nov 9, 2010 at 14:04

1 Answer 1

2
$\begingroup$

Suppose we have n elements, we want to generate r elements (without order), and want exactly k elements to be repeated.

We can separate the result into a part containing all the repeated elements (the repeating part) and all the rest (the non-repeating part). Suppose the repeating part is of length m. There are $\binom{n}{k}$ ways to choose the distinct elements in the repeating part. Each of them appears at least twice, and the other m−2k elements are arbitrary, so can be chosen in $\binom{m-k-1}{k-1}$ ways. There are $\binom{n-k}{r-m}$ possible choices for the non-repeating part.

Putting it all together:

$\binom{n}{k} \sum_{m=2k}^r \binom{m-k-1}{k-1} \binom{n-k}{r-m}$

If you want to allow less repeating elements, just sum over k as well.

$\endgroup$
2
  • $\begingroup$ I'm trying to absorb this and it seemed I may not have stated that repeats don't have to be contiguous in the problem, does your solution still hold? $\endgroup$
    – harschware
    Commented Jul 20, 2010 at 3:05
  • $\begingroup$ I think so, you can punch in some numbers and check. $\endgroup$ Commented Jul 23, 2010 at 4:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .