Mango Distribution
Given a number of mangoes and number of persons. Find the number of ways to distribute Identical mangoes among identical persons.
Input Specification:
Input: the number of mangoes
input2: the number of persons
Output Specification
Return the number of ways to distribute identical mangoes among identical persons
Example 1:
input: 2
Input: 2
Output: 3
Answers
Given m and n representing number of mangoes and number of people respectively. Task is to calculate number of ways to distribute m mangoes among n people. Considering both variables m and n, we arrive at 4 typical use cases where mangoes and people are considered to be:
1) Both identical
2) Unique and identical respectively
3) Identical and unique respectively
4) Both unique
Explanation:
Case 1: Distributing m identical mangoes amongst n identical people
If we try to spread m mangoes in a row, our goal is to divide these m mangoes among n people sitting somewhere between arrangement of these mangoes. All we need to do is pool these m mangoes into n sets so that each of these n sets can be allocated to n people respectively.
To accomplish above task, we need to partition the initial arrangement of mangoes by using n-1 partitioners to create n sets of mangoes. In this case we need to arrange m mangoes and n-1 partitioners all together. So we need (m+ n-1)! ways to calculate our answer.
Illustration given below represents an example(a way) of an arrangement of partitions created after placing 3 partitioners namely P1, P2, P3 which partitioned all 7 mangoes into 4 different partitions so that 4 people can have their own portion of respective partition:
As all the mangoes are considered to be identical, we divide (m+n-1)! by (m)! to deduct the duplicate entries. Similarly we divide the above expression again by (n-1)! because all people are considered to be identical too.
The final expression we get is : (m+n-1)!/((n-1)!*(m)!)
The above expression is even-actually equal to the binomial coefficient: ^m^+^n^-^1C_n_-_1
hope this answer helps you
Answer:
#include<iostream>
using namespace std;
int fact(int num){
int factorial=1;
for(int i=2;i<=num;i++){
factorial = factorial*i;
}
return factorial;
}
int main(){
int m,n;
cin>>m>>n;
int persons = fact(n-1);
int mongoes = fact(m);
int both= fact(m+n-1);
cout<<(both/((persons)*mongoes))<<" "<<endl;
return 0;
}
Explanation: