(以“ 分类:组合数学 ==摘要== {{信息题|Opposites Attract|http://acm.hust.edu.cn/vjudge/contest/view.action?cid{{=}}70200#problem/J|2|100|time=2015-02-14 15:...”为内容创建页面) |
小 (→摘要: 难度) |
||
| 第2行: | 第2行: | ||
[[分类:组合数学]] | [[分类:组合数学]] | ||
==摘要== | ==摘要== | ||
| − | {{信息题|Opposites Attract|http://acm.hust.edu.cn/vjudge/contest/view.action?cid{{=}}70200#problem/J| | + | {{信息题|Opposites Attract|http://acm.hust.edu.cn/vjudge/contest/view.action?cid{{=}}70200#problem/J|1|100|time=2015-02-14 15:12:53}} |
*来自寒假练习:[http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70200 Special Round for Valentine's Day]J题 | *来自寒假练习:[http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70200 Special Round for Valentine's Day]J题 | ||
*原题链接:http://codeforces.com/problemset/problem/131/B | *原题链接:http://codeforces.com/problemset/problem/131/B | ||
| + | |||
==题意== | ==题意== | ||
每个人有个数值(-10 to 10),数值为相反数的人可以在一起,问能组成对数(每个人可以组成多对)。 | 每个人有个数值(-10 to 10),数值为相反数的人可以在一起,问能组成对数(每个人可以组成多对)。 | ||
| 题目链接 | 难度等级 | 完成状态 | 完成分数 | 最后编辑时间 | 需要注意 |
|---|---|---|---|---|---|
| Opposites Attract | ★☆☆☆☆ | 答案正确 | 100 | 2015-02-14 15:12:53 | 无 |
每个人有个数值(-10 to 10),数值为相反数的人可以在一起,问能组成对数(每个人可以组成多对)。
统计每个数字i对应的人的个数,对于所有
,计算:
并求和。
数值为0的特判一下:
| 131B.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;
}
|