| 题目链接 | 难度等级 | 完成状态 | 完成分数 | 最后编辑时间 | 失误原因(初次提交分数) |
|---|---|---|---|---|---|
| The World is a Theatre | ★☆☆☆☆ | 答案正确 | 100 | 2015-02-14 15:52:05 | 遗漏情况(4) |
有b男g女,选出k个人,使得其中有男>=4女>=1(每个人视作不同)。
高三的排列组合题呀……最简单的想法是排除法:
蠢得要死第一次一不小心把全是女生的情况漏了……
| 131C.cpp代码已折叠
展开折叠内容
|
|---|
#include<cstdio>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<vector>
using namespace std;
#define si(n) scanf("%d",&n)
typedef unsigned long long ll;
#define ci const int&
ll c[100][100]={};
ll C(ci x,ci y)
{
if(!x||!y||x==y)return 1;
if(x<y)return 0;
if(c[x][y])return c[x][y];
return c[x][y]=C(x-1,y)+C(x-1,y-1);
}
int main()
{
int b,g,k;
scanf("%d%d%d",&b,&g,&k);
if(b>=4&&g>=1&&k>=5)
printf("%I64d",C(b+g,k)-C(b,k)-C(b,1)*C(g,k-1)-C(b,2)*C(g,k-2)-C(b,3)*C(g,k-3)-C(g,k));//fixed:漏了C(g,k)//
else
printf("0");
return 0;
}
|