C. The Intriguing Obsession
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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 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 is23 = 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.
题意是:有三个群岛。群岛上面会有a,b,c个岛屿,每个群岛上面的岛屿不能相连,每两个群岛上面的两个或多个岛屿不能同时连接在一个岛屿上面,问在三个群岛中有多少种连接方式。
组合数学:
两两群岛进行组合的连接方式的乘积。
两个群岛中的岛屿进行排列组合一共方式。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
using namespace std;
const int N=5005;
#define mod 998244353
long long int c[N][N];
void init()
{
c[0][0]=1;
for(int i=1;i<=N;i++)
{
c[i][0]=1;
}
for(int i=1;i<N-1;i++)
{
c[i][i]=1;
for(int j=1;j<i;j++)
{
c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;//杨辉三角组合数学的运用
}
}
}
long long int solve(long long int n,long long int m)
{
long long int q=min(n,m);
long long int ans=0;
long long int k=1;
for(long long int i=0;i<=q;i++)
{
if(i!=0)
k=(k*i)%mod;
ans=(ans+(((c[n][i]*c[m][i])%mod)*k)%mod)%mod;
}
return ans;
}
int main()
{
long long int a,b,c;
init();
scanf("%lld%lld%lld",&a,&b,&c);
long long int ans1,ans2,ans3;
ans1=solve(a,b),ans2=solve(a,c),ans3=solve(b,c);
printf("%I64d\n",(((ans1*ans2)%mod)*ans3)%mod);
return 0;
}