Codeforces Round #439 (Div. 2)-The Intriguing Obsession(DP)

来源:互联网 发布:矩阵怎么计算 编辑:程序博客网 时间:2024/05/29 02:12
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 ab 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 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 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.

题意:有三种颜色的岛屿,每种颜色的岛屿有若干个,并且都各不相同,此时岛屿之间可以通过桥连接,

也可以不连接,两个颜色相同的岛屿要么不连接,要么两者之间的距离大于等于3,问你有多少种连接方式。

题解:三种颜色时必须是间隔开来,其实可以看做一次挑两种颜色里的岛屿相连,好吧,其实就是组成二分图。

然而比赛的时候没想到,最后将三种二分图的种数相乘就是答案了。

#include<set>      #include<map>         #include<stack>                #include<queue>                #include<vector>        #include<string>     #include<time.h>    #include<math.h>                #include<stdio.h>                #include<iostream>                #include<string.h>                #include<stdlib.h>        #include<algorithm>       #include<functional>        using namespace std;                #define ll __int64         #define lowbit(x) (x&-x)                #define inf 2147483647             #define mod 998244353          #define maxn  5005   #define eps 1e-9 ll dp[maxn][maxn];int main(void){int i,j,a,b,c;for(i=0;i<=5000;i++)dp[0][i]=1;for(i=1;i<=5000;i++){dp[i][0]=1;for(j=1;j<=5000;j++)dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*j)%mod;}scanf("%d%d%d",&a,&b,&c);ll ans=dp[a][b]*dp[a][c]%mod*dp[b][c]%mod;printf("%I64d\n",(ans+mod)%mod);return 0;}


阅读全文
0 0