I've got a problem where I have N
items with up to D
duplicates for each item. I want to know how many unique sets of K
of the input items I will have given my inputs.
I've got an application that actually generates these unique permutations and works on them, but I'd like to understand how I can compute the number of sets I'll have across various inputs without computing the entire result.
Example (in R):
N <- 19
K <- 4
# Implied D = 3 by just duplicating it in-place three times.
a <- append(a:N, append(1:N, 1:N))
b <- unique(permutations(length(a), K, a, set=FALSE))
nrow(b)
in this case will be 130,302
.
This is slow and inelegant. Can someone help me do this with actual math?