Description
There 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.
Sample Input
5 2 5
10
4 3 5
3
小结:
大概的想法有两种:DP,以及排列组合,两者都可以...基本属于水题范畴,为了方便理解,我两种想法的AC代码如下:
排列组合:
#include<stdio.h>
#include<string.h>
int min(int a,int b)
{
return a<b?a:b;
}
long long solve(int a,int b)
{
if(a>b)
return 0;
int temp=min(b-a,a);
long long ans=1;
for(int i=1;i<=temp;i++)
{
ans*=(b--);
ans/=i;
}
return ans;
}
int main()
{
int m,n,t;
scanf("%d%d%d",&m,&n,&t);
long long ans=0;
for(int i=4;i<t;i++)
{
ans+=solve(i,m)*solve(t-i,n);
}
printf("%lld\n",ans);
return 0;
}
DP:
#include<stdio.h>
#include<string.h>
int main()
{
int n,m,t;
scanf("%d%d%d",&n,&m,&t);
long long dp[65][65];
memset(dp,0,sizeof(dp));
for(int i=0;i<=30;i++)
{
dp[i][0]=1;
for(int j=1;j<=i;j++)
{
dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
}
}
long long ans=0;
for(int i=4;i<t;i++)
{
ans+=dp[n][i]*dp[m][t-i];
}
printf("%lld\n",ans);
return 0;
}