Codeforces Beta Round #95 (Div. 2) C 组合数学
2 seconds
256 megabytes
standard input
standard output
There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.
Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.
The only line of the input data contains three integers n, m, t (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).
Find the required number of ways.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
5 2 5
10
4 3 5
3 题意:n个男生 m个女生 选t个人 男生最少4个 女生最少1个 问有多少种选择方式 题解:组合数学 数据范围很小 求组合数 直接公式线性处理或者杨辉三角处理 C(n,m)=n!/m!(n-m)!
注意在男生为4,女生为1的基础上暴力求。枚举男生的人数i=(4~t-1)ΣC(n,i)*C(m,t-i)
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
ll n,m,t;
ll ans;
ll combine1(ll n,ll m) //计算组合数C(n,m)
{
ll sum=; //线性计算
for(ll i=,j=n;i<=m;i++,j--)
sum=sum*j/i;
return sum;
}
int main()
{
scanf("%I64d %I64d %I64d",&n,&m,&t);
for(int i=;i<=t-;i++)
{
ans=ans+combine1(n,i)*combine1(m,t-i);
}
printf("%I64d\n",ans);
}
最新文章
- 执行动态sql返回参数
- js将数字转换成大写的人民币表达式
- c#观察者模式学习笔记(1)
- git branch(转)
- 克隆虚拟机win8系统后注意修改安全标识(SID)
- httpClient 发送请求后解析流重用的问题(HttpEntity的重用:BufferedHttpEntity)
- 学习CSS记录:选择符优先级
- LVS的NAT模式测试
- 关于Oracle-SQL语句性能优化
- CASE WHEN 高阶用法?
- JAVA WEB开发环境与搭建
- Appium(二)---启动App+模拟滑动
- 分享一个前后端分离的web项目(vue+spring boot)
- spring boot默认访问静态资源
- JMeter 脚本开发(五)
- jvm的调优
- Pandas初学者代码优化指南
- String、StringBuffer、StringBuilder和StringTokenizer的区别
- Java Future源码分析
- sublime配置
热门文章
- Symmetric Difference-freecodecamp算法题目
- C++ 容器与继承
- 基于Qt Creator实现中国象棋人机对战, c++实现
- LGTB 学分块
- 二、Linux 系统启动过程
- Linux时区修改
- 第39-43课 thinkphp5完成商品会员价格功能(后置勾子afterInsert)
- Java总结 - List实现类ArrayList&;LinkedList
- python3+openCV实现图片的人脸人眼检测,原理+参数+源代码
- Find a path HDU - 5492 (dp)