Is there a general formula which can tackle the following:

givennobjects andrspots, I want to calculate the number of possible combinations accounting for duplicates and repetition.

eg. n = 4, r = 3 (AAAB)

possible combinations:

AAA

AAB

result is 2

eg. n = 4, r = 3 (AABC)

possible combinations:

AAB

AAC

ABC

result is 3

eg. n = 5, r = 3 (AABBC)

possible combinations:

AAB

AAC

ABB

ABC

BBC

result is 5

Thank you