Just google about it, and it seems like a derangement for multiset. See

http://en.wikipedia.org/wiki/Derangement

for the generalization part. As someone in the other forum suggested (and listed in the above wiki page as well) it involves the integration of a certain polynomial. I have just read this method, maybe other experts here could help.