Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学

来源:互联网 发布:windows mobile 编辑:程序博客网 时间:2024/06/16 08:21

C. The Intriguing Obsession
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

— 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 aband 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.

Input

The first and only line of input contains three space-separated integers ab and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.

Output

Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.

Examples
input
1 1 1
output
8
input
1 2 2
output
63
input
1 3 5
output
3264
input
6 2 9
output
813023575
Note

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;}



阅读全文
0 0
原创粉丝点击