Given two integers N and R, the task is to calculate the number of ways to distribute N identical objects into R distinct groups.
Input: N = 4, R = 2
No of objects in 1st group = 0, in second group = 4
No of objects in 1st group = 1, in second group = 3
No of objects in 1st group = 2, in second group = 2
No of objects in 1st group = 3, in second group = 1
No of objects in 1st group = 4, in second group = 0
Input: N = 4, R = 3
Approach: Idea is to use Multinomial theorem. Let us suppose that x1 objects are placed in the first group, x2 objects are placed in the second group and xR objects are placed in the Rth group. It is given that,
x1 + x2 + x3 +…+ xR = N
The solution of this equation by multinomial theorem is given by N + R – 1CR – 1.
Below is the implementation of the above approach:
Time Complexity: O(R)
- Number of ways of distributing N identical objects in R distinct groups with no groups empty
- Number of ways to arrange K different objects taking N objects at a time
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Ways of dividing a group into two halves such that two elements are in different groups
- Number of Groups of Sizes Two Or Three Divisible By 3
- Print a number strictly less than a given number such that all its digits are distinct.
- Find the number of ways to divide number into four parts such that a = c and b = d
- Count number of ways to divide a number in 4 parts
- Number of ways to get a given sum with n number of m-faced dices
- Number of ways to choose a pair containing an even and an odd number from 1 to N
- Distributing M items in a circle of size N starting from K-th position
- Number of distinct subsets of a set
- Check whether a number has exactly three distinct factors or not
- Number of distinct integers obtained by lcm(X, N)/X
- Count number of distinct substrings of a given length
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.