C. The World is a Theatre

来源:互联网 发布:社交网络电影ppt 编辑:程序博客网 时间:2024/06/01 08:36

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 nmt (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 test(s)
input
5 2 5
output
10
input
4 3 5
output
3

解题说明:这道题是一道典型的DP问题,按照DP问题的解法,无非是先打表然后判断指定位置情况。在本题中,我们用c[i][j]来表示从i个人中选择j个人当演员的候选数,于是我们可以得到下面转移方程:

c[i][j]=c[i-1][j-1]+c[i-1][j];

也就是要么是从i-1个人中选j-1个,再加上第i个;要么是从i-1个中选j个。最终结果就是统计从i=4开始直到t-1结束时c[n][i]*c[m][t-i]的和【i取值原因是至少要4个男孩和1个女孩】

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;long long c[64][64];long long res;int main(){int n,m,t;int i,j;scanf("%d %d %d",&n,&m,&t);for(i=0;i<=30;i++) {c[i][0]=1;for(j=1;j<=i;j++){c[i][j]=c[i-1][j-1]+c[i-1][j];}}res=0;for( i=4;i<t;i++){res += c[n][i]*c[m][t-i];}printf("%lld\n",res);return 0;}


 

原创粉丝点击