C. The World is a Theatre
来源:互联网 发布:社交网络电影ppt 编辑:程序博客网 时间:2024/06/01 08:36
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.
The only line of the input data contains three integers n, m, t (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).
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.
5 2 5
10
4 3 5
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;}
- C. The World is a Theatre
- The World is a Theatre
- CodeForces 131C The World is a Theatre 组合数
- E - The World is a Theatre
- E - The World is a Theatre
- The World is a Theatre codeforces131c
- 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
- Got an exception - expecting xxx found EOF
- Eclipse调试Java的10个技巧
- ios左右菜单PPRevealSideviewController使用的一些心得
- 网络事故分析
- MySQL——修改root密码的几种方法
- C. The World is a Theatre
- 直接拿来用!最火的iOS开源项目(一)链接地址
- error prj0003 不能生成cl.exe的解决方法
- 直接拿来用!最火的iOS开源项目(二)链接地址
- .NET基础扩展系列-事件的实现原理
- SQLPLUE命令
- 直接拿来用!最火的iOS开源项目
- 开源DirectUI界面库
- ASP.NET中防止Access数据库下载