2013 - ECJTU 暑期训练赛第三场-problem-D
2013-07-15 20:48
344 查看
D -
D
Submit
Status
Practice
POJ 3070
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
Input
Output
Input
Output
D
Submit
Status
Practice
POJ 3070
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
Input
5 2 5
Output
10
Input
4 3 5
Output
3
组合数学问题,记住一个公式,这道题就迎刃而解了,Cn(m)=C(n-1)(m-1)+C(n-1)m
AC代码:
#include<stdio.h> #define MAX 61 __int64 s[MAX][MAX]; int main() { int i,j,n,m,t; __int64 sum; s[1][1]=1; for(i=60;i>=1;i--)//初始化,因为Cn(1)=n s[1][i]=i; for(i=60;i>=1;i--)//同样,因为Cn(n)=1 s[i][i]=1; for(i=2;i<=60;i++) { for(j=2;j<=60;j++) { if(j>=i) s[i][j]=s[i-1][j-1]+s[i][j-1];//Cm(n)=C(m-1)(n-1)+Cm(n-1),我这里反过来了本来是Cn(m)=C(n-1)(m-1)+C(n-1)m } } while(scanf("%d%d%d",&n,&m,&t)!=EOF) { sum=0; for(i=4;i<=n;i++) { for(j=1;j<=m;j++) { if((i+j)==t) { sum+=s[i] *s[j][m]; } } } printf("%I64d\n",sum); } return 0; }
相关文章推荐
- 2013 - ECJTU 暑期训练赛第三场-problem-J
- 2013 - ECJTU 暑期训练赛第三场-problem-B
- 2013 - ECJTU 暑期训练赛第三场-problem-E
- 2013 - ECJTU 暑期训练赛第三场-problem-L
- 2013 - ECJTU 暑期训练赛第三场-problem-K
- 2013 - ECJTU 暑期训练赛第三场-problem-H
- 2013 - ECJTU 暑期训练赛第三场-problem-F
- 2013 - ECJTU 暑期训练赛第二场-problem-A
- 2013 - ECJTU 暑期训练赛第六场-problem-G
- 2013 - ECJTU 暑期训练赛第二场-problem-E
- 2013 - ECJTU 暑期训练赛第七场-problem-F
- 2013 - ECJTU 暑期训练赛第二场-problem-G
- 2013 - ECJTU 暑期12级训练赛第一场-Problem-H
- 2013 - ECJTU 暑期训练赛第四场-problem-C
- 2013 - ECJTU 暑期训练赛第七场-problem-G
- 2013 - ECJTU 暑期训练赛第二场-problem-H
- 2013 - ECJTU 暑期12级训练赛第一场-Problem-A
- 2013 - ECJTU 暑期训练赛第二场-problem-J
- 2013 - ECJTU 暑期训练赛第四场-problem-L
- 2013 - ECJTU 暑期12级训练赛第一场-problem-B