C. The World is a Theatre
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputThere are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.
Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.
Input
The only line of the input data contains three integers n, m, t (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).
Output
Find the required number of ways.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
5 2 5
Output
10
Input
4 3 5
Output
3
题意:n个男生 m个女生 选t个人 男生最少4个 女生最少1个 问有多少种选择方式
题解:组合数学 数据范围很小 求组合数 直接公式线性处理或者杨辉三角处理 C(n,m)=n!/m!(n-m)!
注意在男生为4,女生为1的基础上暴力求。枚举男生的人数i=(4~t-1)ΣC(n,i)*C(m,t-i)
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #define ll long long 5 using namespace std; 6 ll n,m,t; 7 ll ans; 8 ll combine1(ll n,ll m) //计算组合数C(n,m) 9 { 10 ll sum=1; //线性计算 11 for(ll i=1,j=n;i<=m;i++,j--) 12 sum=sum*j/i; 13 return sum; 14 } 15 int main() 16 { 17 scanf("%I64d %I64d %I64d",&n,&m,&t); 18 for(int i=4;i<=t-1;i++) 19 { 20 ans=ans+combine1(n,i)*combine1(m,t-i); 21 } 22 printf("%I64d ",ans); 23 }