CF869C:C. The Intriguing Obsession(组合数)
来源:互联网 发布:数据库mdf文件过大 编辑:程序博客网 时间:2024/06/06 18:15
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
The first and only line of input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.
Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.
1 1 1
8
1 2 2
63
1 3 5
3264
6 2 9
813023575
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
思路:首先同一集合内的点不能建边,一个点不能伸出>=2条边到同一个集合内,那么对于两个集合,要建边就得各自贡献相同的点数了,枚举下即可。
# include <iostream># include <cstdio># include <algorithm>using namespace std;typedef long long LL;const LL mod = 998244353;const int maxn = 5003;LL inv[maxn+3] = {1,1}, fac[maxn+3] = {1,1}, fi[maxn+3] = {1,1};void init(){ for(int i=2; i<=maxn; ++i) { fac[i] = fac[i-1]*i%mod;//阶乘 inv[i] = (mod-mod/i)*inv[mod%i]%mod;//逆元 fi[i] = fi[i-1]*inv[i]%mod;//逆元阶乘 }}LL C(LL n, LL m){ return fac[n]*fi[m]%mod*fi[n-m]%mod;}inline mu(LL &a, LL b){ a *= b; if(a >= mod) a %= mod;}int main(){ init(); LL a, b, c; scanf("%lld%lld%lld",&a,&b,&c); LL ans1=1, ans2=1, ans3=1; for(int i=1; i<=min(a,b); ++i) { LL tmp = 1; mu(tmp, C(a, i)); mu(tmp, C(b, i)); mu(tmp, fac[i]); ans1 += tmp; ans1 %= mod; } for(int i=1; i<=min(a,c); ++i) { LL tmp = 1; mu(tmp, C(a, i)); mu(tmp, C(c, i)); mu(tmp, fac[i]); ans2 += tmp; ans2 %= mod; } for(int i=1; i<=min(c,b); ++i) { LL tmp = 1; mu(tmp, C(c, i)); mu(tmp, C(b, i)); mu(tmp, fac[i]); ans3 += tmp; ans3 %= mod; } LL ans = 0; ans = (ans + ans1*ans2%mod*ans3%mod)%mod; printf("%lld\n",ans); return 0;}
- CF869C:C. The Intriguing Obsession(组合数)
- cf869C The Intriguing Obsession
- Codeforces Round #439 C. The Intriguing Obsession (组合数)
- Codeforces-869C The Intriguing Obsession(DP/组合数)
- Codeforces 869C The Intriguing Obsession【组合数】
- Codeforces Round #439C 组合数-The Intriguing Obsession
- Codeforces Round #439 (Div. 2)C. The Intriguing Obsession (组合数详解)
- Codeforces 869 C. The Intriguing Obsession (组合数学)
- Codeforces Round #439 C.The Intriguing Obsession(组合数学)
- [codefoces439C]The Intriguing Obsession(组合数学)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(组合数)
- Codeforces Round #439 (Div. 2) C.The Intriguing Obsession(组合数、记忆化搜索)
- codeforces 869C The Intriguing Obsession 组合数学,逆元
- codeforces 869C. The Intriguing Obsession(组合数学)
- codeforces 869C The Intriguing Obsession 组合数学
- 【Codeforces 869 C The Intriguing Obsession】& 组合数学 & 思维
- #439 Div.2 C. The Intriguing Obsession 组合数学
- Codeforces Round439 C.The Intriguing Obsession
- 从零开始前端学习[30]:Css3中新增加的选择器二
- HDU 1176
- Codeforces Round #439 (Div. 2)A,B
- ubuntu16.04配置vncserser中常见的问题
- 各大公司Java后端开发面试题总结
- CF869C:C. The Intriguing Obsession(组合数)
- Hankson 的趣味题——唯一分解定律
- 开发板之按键中断流程
- 前端面试碰到过的面试题和笔试题~
- 03动态规划基础---机器人走方格问题
- 2017.10.10 取石子游戏 失败总结
- IE6,IE7,IE8,IE9,FIREFOX,Chrome等浏览器兼容详解收集
- 深度神经网络模型压缩
- Java面试题全集(4)