Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
来源:互联网 发布:windows mobile 编辑:程序博客网 时间:2024/06/16 08:21
— 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, band 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.
有三类不同的点。现在给出每种点的个数,要求连边组成无向图,统计使得任意两个相同颜色的点之间距离至少为3或者不连通的连边方案数。
对于任意两堆之间,连边的方案数是独立的。所以,我们只要单独考虑12,13,23每对点堆分别连边的方案数,再乘起来。
对于每两堆,假设各有a,b个点。(a>b)
两堆间连一条边,显然有C(b,1)*a种。
连第二条边,有C(b,2)*a*(a-1)种。
.......
连第b条边,有C(b,b)*a*(a-1)*...*(a-b+1)种。
最后加起来就是总数。
#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <deque>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#include <iomanip>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;typedef double db;const int maxn=5005,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f,mod=998244353; const ld pi=acos(-1.0L);ll C[maxn][maxn];int main() {ll a,b,c,i,j;cin >> a >> b >> c;C[0][0]=1;for (i=1;i<=5000;i++) {C[i][0]=1;for (j=1;j<=i;j++) {C[i][j]=C[i-1][j]+C[i-1][j-1];C[i][j]%=mod;}}if (a<b) swap(a,b);if (a<c) swap(a,c);if (b<c) swap(b,c);ll na,nb,nc,l;l=1;na=nb=nc=1;for (i=a;i>=a-b+1;i--) {l*=i;l%=mod;na+=l*C[b][a-i+1];na%=mod;//cout << na << endl;}l=1; for (i=a;i>=a-c+1;i--) {l*=i;l%=mod;nb+=l*C[c][a-i+1];nb%=mod;}l=1;for (i=b;i>=b-c+1;i--) {l*=i;l%=mod;nc+=l*C[c][b-i+1];nc%=mod;}ll ans=(((na*nb)%mod)*nc)%mod;printf("%I64d\n",ans);return 0;}
- 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 组合数学
- Codeforces Round #439 C.The Intriguing Obsession(组合数学)
- 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 (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(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(组合数、记忆化搜索)
- codeforces 869C The Intriguing Obsession 组合数学,逆元
- Codeforces 869 C. The Intriguing Obsession (组合数学)
- codeforces 869C. The Intriguing Obsession(组合数学)
- java面试题及答案
- 【Leetcode】252,253 meeting room系列 区间问题
- UVA
- Python之——Eclipse +PyDev开发python,import其他模块时eclipse会报错,运行却没有问题
- Lua泛型for
- Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
- hdu 5646 拆数积最大 数学
- 5. 抽象工厂模式
- QT的信号和槽函数的使用(一)
- 17.10.7日报
- PHP explode() 函数
- [BZOJ2957]楼房重建-线段树
- 如何使用mybatis调用存储过程
- C++简单的矩阵运算