— 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.
题意:有三种颜色的岛屿,其中同种颜色的岛屿之间的距离>=3(即不能连同一个) . 考虑到,任意两种颜色直接的方案与其他组合无关 . 那么根据组合数学的知识,我们可以得到两种颜色的方案数为sigma(c[a][i]*c[b][i]*fac[i])
#include<bits/stdc++.h>
#define bug cout <<"bug"<<endl;
#define read(x) scanf("%d",&x)
using namespace std;
typedef long long ll;
const int MAX_N=5005;
const int MOD=998244353;
const int INF=0x3f3f3f3f;
ll fact[MAX_N];
ll c[MAX_N][MAX_N];
ll cul(ll a,ll b){
ll k=min(a,b);
ll ans=0;
for(ll i=0;i<=k;i++){
ans+=(c[a][i]*c[b][i]%MOD*fact[i])%MOD;
ans%=MOD;
}
return ans;
}
void init(){
fact[0]=1;
for(int i=1;i<=5000;i++) fact[i]=i*fact[i-1]%MOD;
c[0][0]=c[1][0]=c[1][1]=1;
for(int i=2;i<=5000;i++){
c[i][0]=1;
for(int j=1;j<=5000;j++)
c[i][j]+=(c[i-1][j]+c[i-1][j-1])%MOD,c[i][j]%=MOD;
}
return ;
}
int main(void){
init();
ll a,b,c;
cin >> a >> b >>c;
cout << cul(a,b)%MOD*cul(a,c)%MOD*cul(b,c)%MOD << endl; //注意取模
return 0;
}