codeforces 131c 组合数
来源:互联网 发布:前苏联十大实验知乎 编辑:程序博客网 时间:2024/05/22 09:04
题目:
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
利用组合数递推公式:C(n, m) = C(n - 1, m - 1) + C(n - 1, m) 对应最后一个选或者不选的情况
代码:
#include<bits/stdc++.h>using namespace std;const int maxn=70;///只开到35的话 20 20 40 这组样例会因为越界报错__int64 n,m,t;__int64 c[maxn][maxn];int main(){ memset(c,0,sizeof(c)); c[0][0]=1; for(int i=1;i<=30;++i){ c[i][0]=c[i][i]=1; for(int j=1;j<=i;++j){ c[i][j]=c[i-1][j-1]+c[i-1][j]; } } /*for(int i=0;i<=30;++i){ for(int j=0;j<=30;++j){ cout<<c[i][j]<<" "; } cout<<endl; }*/ scanf("%I64d%I64d%I64d",&n,&m,&t); __int64 ans=0; for(__int64 i=4;i<t;++i){ ans+=c[n][i]*c[m][t-i];///若判一下i和n的关系以及m和t-1的关系数组就可以开小一些 } printf("%I64d\n",ans); return 0;}
也可以使用递推公式每次算一下,不过会慢一些:
#include<bits/stdc++.h>using namespace std;__int64 n,m,t;__int64 C(__int64 n,__int64 m){ __int64 ans=1; for(__int64 i=1;i<=m;++i){ ans*=(n-i+1); ans/=i; } return ans;}int main(){ scanf("%I64d%I64d%I64d",&n,&m,&t); __int64 ans=0; for(__int64 i=4;i<t;++i){ ans+=C(n,i)*C(m,t-i); } printf("%I64d\n",ans); return 0;}
- CodeForces 131C--组合数
- codeforces 131c 组合数
- CodeForces 131C The World is a Theatre 组合数
- codeforces 630~~【组合数 C(n,m)】
- Codeforces #355C (Div. 2) 组合数
- codeforces contest 869 problem C(组合数)
- codeforces 869c(组合数)
- codeforces 869c(组合数)
- [刷题笔记] Codeforces 131C 组合数的写法+平均数防爆
- codeforces 341C Iahub and Permutations(组合数dp)
- Codeforces Round #439 C. The Intriguing Obsession (组合数)
- Codeforces 869C The Intriguing Obsession【组合数】
- Codeforces Round #439C 组合数-The Intriguing Obsession
- Codeforces-869C The Intriguing Obsession(DP/组合数)
- CodeForces 554C 组合数学
- codeforces 294C组合数学)
- Codeforces Beta Round #22 (Div. 2 Only), problem: (C) System Administrator 图论+组合数
- Codeforces Round #157 (Div. 1)C(因数分解+二分+组合数)
- solr管理界面详解
- 字母小游戏
- 关键字static的作用
- php上传文件
- poj 2395 Out of Hay (最小生成树)
- codeforces 131c 组合数
- java中的Maven项目的打包成jar或者war
- WEB服务器:利用python CGI实现简单的微信后台服务器
- Linux系统服务的控制
- 朴素贝叶斯(离散型+连续型)
- 正则表达式
- 如何实现英语课程微信预约系统?
- 数论-判断素数,输出素数,最短时间
- 快排专题 HDU—1862