The number of "combinations" of four elements chosen from $ABC$ where the order does matter is $3^4$ - the first element can be chosen in three ways, the second also in three ways and the third in three ways etc.
This includes combinations which do not contain all three letters. They might contain $AB$ only - this can happen in $2^4$ ways, or $BC$, or $AC$ similarly - $3\times 2^4$
But both $AB$ and $BC$ produce the combination $BBBB$, which has therefore been counted twice, and similarly for $AAAA$ and $CCCC$ - so we have to add back $3\times 1$
So the answer is $3^4-3\times 2^4+3\times 1^4=81-48+3=36$
This is a simple application of the inclusion-exclusion principle. This is clearer if we write the expression as:$$\binom 3 3 3^4-\binom 3 2 2^4+\binom 3 1 1^4 -\binom 30 0^4$$
$\binom 32$ arises, for example, because we took three pairs of letters from $ABC$ at the second stage, and this can be done in $\binom 32=3$ ways. I pinched the last term from the answer given by Tomas - we don't need it - it is zero - but it does show where the final binomial coefficient goes.
A second way of counting in this instance is to see that if a combination of four letters contains each of $ABC$ then it has just one doubled letter. This can be chosen in three ways. Then we place the letters by choosing a place for $A$ if it is undoubled, or $B$ if $A$ is doubled. This can be done in four ways. The second single letter can then be placed in one of the three remaining places - three ways.
The number of combinations is then $3 \times 4 \times 3 = 36$
n to the power of r
in the title and in the first and third case of the suggested formula, andfact n / fact (n-r) * fact r
for the middle case in the formula. $\endgroup$