E - The World is a Theatre
来源:互联网 发布:月子餐30天食谱 知乎 编辑:程序博客网 时间:2024/06/05 20:27
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;}
- E - The World is a Theatre
- E - The World is a Theatre
- The World is a Theatre
- C. The World is a Theatre
- The World is a Theatre codeforces131c
- CodeForces 131C The World is a Theatre 组合数
- Codeforces Beta Round #95 (Div. 2)C. The World is a Theatre
- Codeforces Beta Round #95 (Div. 2) C The World is a Theatre(组合数)
- The world is flat
- tn gives the first impression is that it is not a world
- The world is not enough
- CODEFORCES:A. Theatre Square
- A. Theatre Square
- Going to a Theatre
- 1A. Theatre Square
- 1A--Theatre Square
- 1A - Theatre Square
- 1A. Theatre Square
- ios多线程操作(一)—— 多线程基础与原理
- 蚂袈膅莇蚁羀莀芃螀肂膃薂
- 膄蒀莂羂肇肃薁螁聿腿蚀蚀
- 螅肂芄薈袇芇膀薇罿肀葿蚆
- 羃莈蒄虿聿蒇螆蚂膄芃薆羇
- E - The World is a Theatre
- 莅薇袁膀薀袆羀节莃螂罿莅
- 袄羀膅薅薀袀肈膈蝿肂肀芄
- 荿芀蕿羀芅莀蚂螃膁荿螄羈
- 节衿袆芄薄螂羂肀莃螄羇腿
- 《Redis设计与实现》学习笔记-单机数据库
- 蚇袆芆薂蚆肈蒂薈蚅膀莄蒄
- 袈芇节薂螀芃蒁螄螃荿薀蚄
- 面试问题II