Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(组合数)
来源:互联网 发布:航悦淘宝上的冰冰精华 编辑:程序博客网 时间:2024/06/06 09:49
题意:有三种颜色的点,告诉你三种颜色的点的个数a,b,c,问你有多少种方式建边,要求是相同颜色的点不能到
达,或者相同颜色点互相到达的距离至少为3,每条边的长度为1。 (a, b, c <= 5e3)
思路:我们知道同一颜色的点之间是不可能建边的,所以我们可以两两颜色之间考虑。对于颜色a,b之间,我们可以
知道一个点不可能连两条边,因为如果一个点连两条边这样相同颜色距离就为2了。所以每个点只能连对面颜色一个
点。这样我们就可以枚举连边的点的个数k,两边各取k个C(numa, k)*C(numb, k),因为会交叉连边,所以还要乘上k!,
所以∑C(numa, k)*C(numb, k)*k!就是两种颜色间的方案数。
同理计算下a与c,b与c,最后三者相乘即可。
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int mod = 998244353;const int maxn = 5e3+5;ll c[maxn][maxn], fac[maxn] = {1};void init(){ c[0][0] = 1; for(int i = 1; i < maxn; i++) for(int j = 0; j <= i; j++) { if(!j || i == j) c[i][j] = 1; else c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod; } for(int i = 1; i < maxn; i++) fac[i] = fac[i-1]*i%mod;}int main(void){ init(); int a[3]; while(cin >> a[0] >> a[1] >> a[2]) { ll ans = 1; for(int i = 0; i < 3; i++) for(int j = i+1; j < 3; j++) { ll tmp = 1; for(int k = 1; k <= min(a[i], a[j]); k++) tmp = (tmp+c[a[i]][k]*c[a[j]][k]%mod*fac[k]%mod)%mod; ans = ans*tmp%mod; } printf("%I64d\n", ans); } return 0;}
阅读全文
1 0
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(组合数)
- Codeforces Round #439 (Div. 2)C. The Intriguing Obsession (组合数详解)
- Codeforces Round #439 (Div. 2) C.The Intriguing Obsession(组合数、记忆化搜索)
- Codeforces Round #439 C. The Intriguing Obsession (组合数)
- Codeforces Round #439C 组合数-The Intriguing Obsession
- Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession dp
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(dp)
- Codeforces Round #439 (Div. 2) 869 C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C 869C The Intriguing Obsession(思维+简单组合)
- Codeforces Round #439 (Div. 2) C The Intriguing Obsession (组合数学)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #439 C.The Intriguing Obsession(组合数学)
- Codeforces Round #439 (Div. 2)-The Intriguing Obsession(DP)
- 提升用户体验的的网站解决方案:门户极端案列之大并发写入案列 (主要是讲缓存案列)
- 反射访问构造方法
- thinkphp5的入门学习
- python学习笔记
- 错误: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer c
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(组合数)
- 打造可监控的线上应用dropwizard-metrics
- 程序铮ios探索之路(一)
- sublime一款强大的文本编辑器,小白入手教程
- 蓝桥杯 算法提高 笨小猴
- CMM语言解释器构造实践(二)——JavaCC等编译工具的使用
- android编辑框
- Single Number
- Eclipse中关联和生成javadoc文档