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; ...
随机推荐
- P1059 C语言竞赛
P1059 C语言竞赛 转跳点:
- PG、GP与MySQL的特点和区别
参考 PostgreSQL数据库 介绍:PostgreSQL是一种运行在Unix和Linux操作系统(在NT平台借助Cygnus也可以运行)平台上的免费的开放源码的关系数据库.最早是由美国加州大学伯克 ...
- Microsoft Windows 实用程序 Sysinternals Utilities Index
最新页面时间:2017年5月16日 Sysinternals被MS收购--windows internals共近70多个工具集 Sysinternals套件 整套Sysinternals Utilit ...
- JuJu alpha
JuJu alpha阶段总结博客 JuJu 设想与目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 在cao ying researcher给的资料中定 ...
- Golang的选择结构-switch语句
Golang的选择结构-switch语句 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.选择语句应用场景概述 选择结构也称为条件判断,生活中关于判断的场景也非常的多,比如: ( ...
- 破解centos7 密码
1.在CentOS7的启动选项,按“e”选择编辑启动选项2.进入下图画面,点下箭头直到看到“linux162174542514”,按end键跳到行尾3.在行尾加上“rd.break”,并敲击键盘“ct ...
- R函数
1. sd() 求一组数据的标准差 > x = rep(1,15) > x [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > sd(x) [1] 0 2.var ...
- JVM探秘:jstack查看Java线程状态
本系列笔记主要基于<深入理解Java虚拟机:JVM高级特性与最佳实践 第2版>,是这本书的读书笔记. jstack命令可以打印Java进程的各个线程堆栈跟踪信息,可以用来查看Java中各个 ...
- APIO 2010 特别行动队 斜率优化DP
Description 你有一支由 n 名预备役士兵组成的部队,士兵从 1 到 n 编号,要将他们拆分 成若干特别行动队调入战场.出于默契的考虑,同一支特别行动队中队员的编号 应该连续,即为形如 (i ...
- C#使窗体不显示在任务栏
this.ShowInTaskbar = false;///使窗体不显示在任务栏