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; ...
随机推荐
- ROS学习笔记3-基础课程之文件系统向导
准备工作需要使用如下命令安装ros的教程: $ sudo apt-get install ros-<distro>-ros-tutorials 其中,distro为所用ros的发行版本,该 ...
- STM32F103 USB虚拟串口 驱动例程移植
1)驱动下载及安装.目前ST公司支持WIN7版本号为:VCP_V1.3.1_Setup.exe (在官网上搜索stsw-stm32102即是了):先安装驱动后再插入USB不然安装不成功. 2)固件下载 ...
- 将证书添加到受信任的根证书存储失败,出现以下错误:访问控制列表(ACL)结构无效
问题出现情景: 使用 vs2017 创建一个 ASP.NET Core Web 应用程序 -> Ctrl + F5 运行项目 选择是,但是添加证书失败,是什么原因导致的我不知道,有大佬的知道的话 ...
- HTML<figure> <figcaption> 标签定义图文并茂
本来想分两篇文章来解释说明figure.figcaption的,但是这俩个标签都是定义图文的,所以我们合起来讲解,大家更能容易接受. 大家在写xhtml.html中常常用到一种图片列表,图片+标题 或 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-star-empty
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 05 MySQL数据类型的选择与使用
数据类型的选择 1.CHAR与VARCHAR 存储/检索的方式不同. CHAR是固定长度,而VARCHAR是可变长度 非SQLMode下,超 ...
- scanf与正则表达式的搭配及应用
scanf与正则表达式的搭配及应用 正则其实我也学的不咋地,只会一点皮毛,正则最大的作用就是当输入流是一个字符串,我们能在输入的时候就滤掉无用信息,省去后期提取数值的步骤. 正则的语法我怕误人子弟,嘿 ...
- 锤子科技向OpenBSD基金会捐款195 万
导读 专注于提供 OpenBSD 资讯的网站 OpenBSD Journal 昨日报道了锤子科技成为 OpenBSD 基金会 2019 年首位铱金捐赠者的消息. 根据 OpenBSD Journal ...
- Spark tungsten 项目阅读笔记
Spark tungsten 项目阅读笔记 Spark tungsten 项目的宣言就是:Bringing Apache Spark closer Bare Metal. 我的理解就是不要让硬件成为S ...
- [ cocos2d-JS ] 启动项目
1, 打开windows命令行 2, cd 到项目的文件夹 3, 执行 cocos run -p web