Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of Different Combination Possible?

You are given number of places as m and number of digits as n. You have to fill those m places in such a way that each digit appears at least one time.

For example

Given m as 4 and n as 3 so you have 4 places and 3 digits. Now For this total possible number of combinations are 36.

Lets take a simple example:

m=3 and n=2(a,b suppose) then possible combinations are

aba aab abb bab bba baa

Thus 6 combinations are possible only. Is there Any Formula for this because I am required to find the possible number of combinations?

like image 525
heema Avatar asked Nov 10 '22 01:11

heema


1 Answers

Answer to the question

The answer is n!S(m,n), where S is Stirling numbers of the second kind.

For example, for m=4, n=3, n!=6, S(4,3)=6, so n!S(m,n)=36 which is the expected answer.

Why this formula?

Stirling numbers of the second kind S(m,n) count the number of ways to partition a set of m elements into n nonempty subsets. So for this question, S(m,n) count the number of ways to partition m places into n groups, each group corresponding to a digit. After the partition, we should designate one digit to each group, and there are n! ways to do this. Therefore, the answer is n!S(m,n).

like image 180
ACcreator Avatar answered Dec 16 '22 01:12

ACcreator