题意:已知有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. nodejs配置 https服务

    const port = normalizePort(process.env.PORT || '3000'); const path = require('path'); const https =  ...

  2. synchronized和锁(ReentrantLock) 区别

    synchronized和锁(ReentrantLock) 区别 java的两种同步方式, Synchronized与ReentrantLock的区别 并发(一):理解可重入锁 可重入锁和不可重入锁 ...

  3. Java笔记--泛型

    1.泛型解决元素存储的安全性问题:解决获取数据元素时,需要类型强转的问题. --泛型的核心思想:把一个集合中的内容限制为一个特定的数据类型. 2.泛型的使用 1)在集合中使用 2)自定义泛型类.泛型接 ...

  4. 杭电oj1859:最小长方形(水题)

    最小长方形 题目链接 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...

  5. Vue父组件向子组件传值

    父组件向子组件传值 组件实例定义方式,注意:一定要使用props属性来定义父组件传递过来的数据 <script> // 创建 Vue 实例,得到 ViewModel var vm = ne ...

  6. apk安装失败的25中原因

    名称 Value 描述 INSTALL_FAILED_ALREADY_EXISTS -1 已经安装 INSTALL_FAILED_INVALID_APK -2 APK文件是无效的 INSTALL_FA ...

  7. HttpClient测试

    导入maven依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson&l ...

  8. Golang的环境安装

    Golang的环境安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Go语言环境安装 1>.下载Golang的安装包 博主推荐阅读: https://studygola ...

  9. maven爬坑

    版本问题 maven源的问题 找不到的jar包 http://www.cnblogs.com/geektown/p/5705405.html http://blog.csdn.net/beyondlp ...

  10. servlet 之 HttpServlet抽象类详解

    Servlet的框架是由两个Java包组成:javax.servlet和javax.servlet.http. 在javax.servlet包中定义了所有的Servlet类都必须实现或扩展的的通用接口 ...