PROBLEM LINK
Flower Bouquet
Author:-Faiz Alam
Editorialist:-Faiz Alam
Tester:-Prasoon Jain
PREREQUISITES
Combinatorics,Maths
PROBLEM
There are n rose flowers and m tulip flowers in the garden . You have to form a flower bouquet using exactly t flowers, in which you have to use minimum of 5 roses and minimum of 2 tulip flowers. Find how many ways are there to form this flower bouquet.
EXPLANATION
Provided that we have to use minimum of 5 roses and 2 tulip flowers and in total t flowers,we can look for all possible combinations that can be made to form bouquet of t flowers using roses ( 5<=no of roses <=n) and tulips (2<=no of tulips <= m).
Example:-
if n=7 ,m=4, t=10
Since, we have to use minimum of 5 roses and 2 tulips and we have to use 10 flowers in this bouquet therefore we can select all 4 tulips along with 6 roses in 7 ways or the other combination would be taking all 7 roses along with 3 tulips in 4 ways . Hence the answer is (7+4) = 11 ways
SOLUTIONS
Setter's Solution
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll factorial(ll n)
{
ll res = 1;
for (ll i = 2; i <= n; i++)
res = res * i;
return res;
}
int main()
{
ll n,m,t;
cin>>n>>m>>t;
ll res=0;
for(ll i=5;i<=t-2;i++)
{
if(m>=t-i && t-i>0 && n-i>=0)
{
res+=((factorial(n)/(factorial(i)*factorial(n-i)))*(factorial(m)/(factorial(t-i)*factorial(m-t+i))) );
}
}
cout<<res<<"\n";
}
Tester's Solution
from math import factorial as f
n,m,t=map(int,input().split())
ans=0
for i in range(5,t-1):
if m>=t-i and t-i>0 and n-i>=0:
ans+=(f(n)//(f(i)*f(n-i)))*(f(m)//(f(t-i)*f(m-(t-i))))
print((ans))
Complexity:-O(N^2)