题意:已知有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(组合数)的更多相关文章

  1. Codeforces 131C . The World is a Theatre(打表组合数)

    题目链接:http://codeforces.com/contest/131/problem/C 大意就是有n个男孩,m个女孩,从男孩中选不少于4个男孩,女孩中选不少于1个女孩,组成人数为t的队伍,问 ...

  2. Codeforces 785D Anton and School - 2(组合数)

    [题目链接] http://codeforces.com/problemset/problem/785/D [题目大意] 给出一个只包含左右括号的串,请你找出这个串中的一些子序列, 要求满足" ...

  3. 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 ...

  4. CodeForces 131C C (组合)

    There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory" ...

  5. 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: ...

  6. codeforces 459C Pashmak and Buses(模拟,组合数A)

    题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...

  7. CodeForces - 140E:New Year Garland (组合数&&DP)

    As Gerald, Alexander, Sergey and Gennady are already busy with the usual New Year chores, Edward has ...

  8. CodeForces - 367E:Sereja and Intervals(组合数&&DP)

    Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. ...

  9. Codeforces 57C (1-n递增方案数,组合数取模,lucas)

    这个题相当于求从1-n的递增方案数,为C(2*n-1,n); 取模要用lucas定理,附上代码: #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. 牛客小白月赛3---G 旅游(树形dp)

    题目链接:https://www.nowcoder.com/acm/contest/87/G 分析: 1.对于点cur,dp[cur][0]表示在该点住宿:dp[cur][1]表示其某个子结点住宿,自 ...

  2. L2-012. 关于堆的判断(最小堆)

    将一系列给定数字顺序插入一个初始为空的小顶堆H[].随后判断一系列相关命题是否为真.命题分下列几种: “x is the root”:x是根结点: “x and y are siblings”:x和y ...

  3. 编程练习:求某个数的n次方,返回其个位和十位

    #!/usr/bin/env python def pow1(n,m): if m==0: return 1 if m==-1: return (1/n) if m & 1 != 0: ret ...

  4. 解决linux下sudo更改文件权限报错xxxis not in the sudoers file. This incident will be reported.

    本文转自Linux社区作者为z-sm的文章 原文链接http://www.linuxidc.com/Linux/2016-07/133066.htm 之前一直使用的是ubuntu,后来安装了Cento ...

  5. [前端] Vue封装播放器、打包、上传NPM

    一.使用icomoon 1.生成和下载图标相关文件 先使用icomoon获取我们要使用的图标,例如播放.暂停.停止.全屏等图标. icomoon网站:https://icomoon.io/app/#/ ...

  6. js加密(十二)yy.com rsa

    1. url: https://aq.yy.com/ 2. target: 登录js 3. 是一个简单的rsa加密,找到加密的js文件,全部复制出来,修改一下就好. 4. 和网页中的一样

  7. Mysql多对多关系的查询

    1.创建user表 2.创建gateway表 3.创建user_gateway表 4.创建device表 5.创建gateway_device表 6.创建一个实体类 public class Devi ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-music

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  9. Spark 下操作 HBase(1.0.0 新 API)

    hbase1.0.0版本提供了一些让人激动的功能,并且,在不牺牲稳定性的前提下,引入了新的API.虽然 1.0.0 兼容旧版本的 API,不过还是应该尽早地来熟悉下新版API.并且了解下如何与当下正红 ...

  10. Golang的单目(一元)运算符-地址操作符和接收操作符

    Golang的单目(一元)运算符-地址操作符和接收操作符 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Golang的单目(一元)运算符概述 常见的地址操作符: &: ...