how to determin number of combinations

hello...

I'm having a bit of problem with one simple task :D First sorry if I put this thread in wrong place :D

I know how to calculate number of combinations (without repetition)

$\displaystyle \frac {n!}{k!(n-k)!}$

and that's ok :D

but now I have big problem :) I have to calculate number of combinations with repetitions :D so i tried like this :D

when i have 2 variables A and B with second expansion i have :

$\displaystyle AA, AB, BA, BB$

so it's four combinations :D

for third expansion i have :

$\displaystyle AAA, AAB, ABA, BAA, BBB, BBA, BAB, ABB$

so there is 8 combinations .... and at first i think formula should be $\displaystyle n^k $ or in my case now $\displaystyle 2^n$ meaning $\displaystyle 2^2 = 4 and 2^3 = 8$ but as I get to problem with 4 variables and need to do third expansion by that formula I need 64 combinations... I wrote all of them and I got 40... now I'm confused very much because in next task I have problem with 10 variables and third expansion ... and there is no way that i can wrote them all to find pattern ....

can anyone please help me with this :D I also find some formulas for similar things but none of them can be any use to me in this problem :D