Description
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.
Input
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
Output one line containing an integer — the number of different ways to build bridges, modulo 998244353.
Examples input
1 1 1
Examples output
8
題意
在三種顏色的島嶼之間建立橋樑,每一種顏色的島嶼分別有 a,b,c a,b,c 個,且相同顏色的島嶼之間距離不能小於 3 3 ,問總共有多少種情況。
思路
顯然,最終橋的排列一定類似於 abcabcabc... abcabcabc... 這樣的,我們將這三種顏色點的集合抽象為空白間中的一個三稜柱。
每條側棱代表一種顏色,每個側面上布著相鄰兩條側棱之間的連線(橋),顯然這樣保證了相同顏色島嶼之間的距離。
我們現在只考慮一個側面,假如相鄰的兩種顏色分別有 a,b a,b 個: 首先,一種顏色不可以與相同的顏色相連,也就是每條側棱中的點之間不能有連線。 第二,不能有相同兩個顏色的點串連到同一個點上,也就是左右兩條側棱之間點的連線無共同起點與終點,顯然這樣的邊最多有 min(a,b) \min(a,b) 個。 第三,橋的數量最少為 0 0 個,最多為 min(a,b) \min(a,b) 個,對於數量為 i i 的橋,我們可以從左邊選取共 (ai) \binom{a}{i} 種方式,從右邊選取共 (bi) \binom{b}{i} 種方式,考慮它們之間的排列共 i! i! 種,於是共有 (ai)×(bi)×i! \binom{a}{i} \times \binom{b}{i} \times i! 種組合。 因此,對於每一個側面,其貢獻 f(a,b)=∑i=min(a,b)i=0(ai)(bi)i! f(a,b)=\sum_{i=0}^{i=\min(a,b)}\binom{a}{i}\binom{b}{i}i! 。
因為三個側面之間的連線是互不干擾的,因此最終的結果為 f(a,b)×f(b,c)×f(c,a) f(a,b) \times f(b,c) \times f(c,a) 。
AC 代碼
#include <bits/stdc++.h>using namespace std;typedef __int64 LL;const int maxn = 5e3+10;const int mod = 998244353;LL mul[maxn];LL inv[maxn];void init(){ mul[0]=1; for(int i=1; i<maxn; i++) mul[i]=(mul[i-1]*i)%mod; inv[0]=inv[1]=1; for(int i=2; i<maxn; i++) inv[i]=(LL)(mod-mod/i)*inv[mod%i]%mod; for(int i=1; i<maxn; i++) inv[i]=(inv[i-1]*inv[i])%mod;}LL C(int n,int m){ return mul[n]*inv[m]%mod*inv[n-m]%mod;}LL mult(int a,int b){ int len = min(a,b); LL ans = 0; for(int i=0; i<=len; i++) ans += C(a,i) * C(b,i) % mod * mul[i] % mod,ans %= mod; return ans;}int32_t main(){ init(); int a,b,c; cin>>a>>b>>c; LL ans = mult(a,b) * mult(b,c) %mod * mult(c,a) %mod; cout<<ans<<endl; return 0;}