CodeForces - 131C The World is a Theatre(组合数)
题意:已知有n个男生,m个女生。现在要选t个人,要求有至少4个男生,至少1个女生,求有多少种选法。
分析:
1、
展开,将分子中的m!与分母中n!相约,即可推出函数C。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e5 + 10;
const int MAXT = 10000 + 10;
using namespace std;
LL C(LL n, LL m){
LL ans = 1;
for(LL i = 1; i <= m; ++i){
ans *= n - i + 1;
ans /= i;
}
return ans;
}
int main(){
LL n, m, t;
while(scanf("%I64d%I64d%I64d", &n, &m, &t) == 3){
LL ans = 0;
for(LL i = 4; i < t; ++i){
ans += C(n, i) * C(m, t - i);
}
printf("%I64d\n", ans);
}
return 0;
}
2、递推求组合数。
高中学的组合数公式:C(n, m) = C(n - 1, m - 1) + C(n - 1, m)。
注意m <= n。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 30 + 10;
const int MAXT = 10000 + 10;
using namespace std;
LL c[MAXN][MAXN];
void init(){
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];
}
}
}
int main(){
LL n, m, t;
init();
while(scanf("%I64d%I64d%I64d", &n, &m, &t) == 3){
LL ans = 0;
for(LL i = 4; i < t; ++i){
if(t - i <= m && i <= n) ans += c[n][i] * c[m][t - i];
}
printf("%I64d\n", ans);
}
return 0;
}
CodeForces - 131C The World is a Theatre(组合数)的更多相关文章
- Codeforces 131C . The World is a Theatre(打表组合数)
题目链接:http://codeforces.com/contest/131/problem/C 大意就是有n个男孩,m个女孩,从男孩中选不少于4个男孩,女孩中选不少于1个女孩,组成人数为t的队伍,问 ...
- Codeforces 785D Anton and School - 2(组合数)
[题目链接] http://codeforces.com/problemset/problem/785/D [题目大意] 给出一个只包含左右括号的串,请你找出这个串中的一些子序列, 要求满足" ...
- Codeforces 785D Anton and School - 2 (组合数相关公式+逆元)
D. Anton and School - 2 time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- CodeForces 131C C (组合)
There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory" ...
- Educational Codeforces Round 80 C. Two Arrays(组合数快速取模)
You are given two integers nn and mm . Calculate the number of pairs of arrays (a,b)(a,b) such that: ...
- codeforces 459C Pashmak and Buses(模拟,组合数A)
题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...
- CodeForces - 140E:New Year Garland (组合数&&DP)
As Gerald, Alexander, Sergey and Gennady are already busy with the usual New Year chores, Edward has ...
- CodeForces - 367E:Sereja and Intervals(组合数&&DP)
Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. ...
- Codeforces 57C (1-n递增方案数,组合数取模,lucas)
这个题相当于求从1-n的递增方案数,为C(2*n-1,n); 取模要用lucas定理,附上代码: #include<bits/stdc++.h> using namespace std; ...
随机推荐
- 定时执行 Job【转】
Linux 中有 cron 程序定时执行任务,Kubernetes 的 CronJob 提供了类似的功能,可以定时执行 Job.CronJob 配置文件示例如下: ① batch/v2alpha1 是 ...
- GoJS实例3
复制如下内容保存到空白的.html文件中,用浏览器打开即可查看效果 <!DOCTYPE html> <html> <head> <meta charset=& ...
- python集成开发环境Anaconda的安装
参考博文: anaconda在Linux下的安装 Linux下anaconda3的安装 Anaconda的安装.启用及停用的步骤 Python学习之Anaconda的使用及配置方法 Anaconda ...
- pytesseract 识别率低提升方法
pytesseract 识别率低提升方法 一.跟换识别语言包 下载地址https://github.com/tesseract-ocr/tessdata 二.修改图片的灰度 from PIL impo ...
- Xcode8.0+和最新的Xcode9.0beta安装Alcatraz插件
1.安装Alcatraz 1.1终端中输入 rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz ...
- Git设置ssh密钥
前提条件是,公司的gitlab,运维没有关闭ssh的权限获取,或者叫运维开通那个ssh权限,生成的公钥要给运维那边一个!这样设置是可以成功 一.创建ssh key 1.在客户端查看有没有密钥 cd ~ ...
- Xmanager 实现图形化安装CentOS7上的软件
Xmanager 是个很不错的工具,集成Xshell,Xftp,Xstart,Xbrowser等常用的远程工具. 当前需求为:有个软件,哑安装(静默安装)方式,在安装时会遇到配置文件加载不全,安装成功 ...
- python基础(三)闭包与装饰器
闭包(closure): 内嵌函数通过调用外部嵌套函数作用域内的变量,则这个内嵌函数就是闭包. 闭包必须满足三个条件: 必须有一个内嵌函数 内嵌函数必须引用外部嵌套函数中的变量 外部函数的返回值必须是 ...
- 《ES6标准入门》(阮一峰)--8.函数的扩展
1.函数参数的默认值 基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console.log ...
- CAN网络上新增加的设备与网络上已有设备MAC地址冲突的软件解决方案
已知 1号的CAN节点的地址是0x1f 2号的CAN 节点的地址是0x1f 要达到的要求是 假设 网络上 CAN1 节点已经工作了,我现在需要在网络上接入CAN2节点. 那么CAN2节点首次上电的时候 ...