codeforces 869c(组合数)

来源:互联网 发布:网络连接流程 编辑:程序博客网 时间:2024/05/22 03:16

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.



题意:有三堆群岛,分别用不同颜色标记,现在在岛间建桥连边,长度统一为1,在限制条件同一种颜色的桥距离最小为三的情况下,有多少种方法建桥(结果模998244353)。

思路:先把三种岛的集合根据岛的数量排序,按照要求一种群岛可以选择其中几个岛向其他群岛中的岛一对一连边,而不能一对多或者多对一,否则则会违反距离最小为3的限制。所以分别讨论两个集合中连边的情况最后在把他们相乘即可。



#include<iostream>#include<stdio.h>#include<string.h>using namespace std;#define maxn  5005__int64 C[maxn][maxn];const int MOD=998244353;void get_C(__int64 x)     //组合数初始化 {        C[0][0] = 1;        for(int i=1;i<=x;i++)        {                C[i][0] = 1;                for(int j=1;j<=i;j++)                C[i][j] = (C[i-1][j]+C[i-1][j-1])%MOD;        }}__int64 jiecheng(int x)     //阶乘 {__int64 ans=1;for(int i=1;i<=x;i++){ans*=i;ans%=MOD;}return ans;}int main(){get_C(5000);int a,b,c;while(~scanf("%d%d%d",&a,&b,&c)){if(a<b)swap(a,b);if(a<c)swap(a,c);if(b<c)swap(b,c);__int64 ans=1;__int64 temp=0;for(int i=0;i<=c;i++)     //a、c连边 {temp+=((C[a][i]*C[c][i]%MOD)*jiecheng(i)%MOD);temp%=MOD;}ans*=temp;ans%=MOD;temp=0;for(int i=0;i<=c;i++)     //b、c连边 {temp+=((C[b][i]*C[c][i]%MOD)*jiecheng(i)%MOD);temp%=MOD;}ans*=temp;ans%=MOD;temp=0;for(int i=0;i<=b;i++)          //a、b连边 {temp+=((C[a][i]*C[b][i]%MOD)*jiecheng(i)%MOD);temp%=MOD;}ans*=temp;ans%=MOD;printf("%I64d\n",ans);}}


原创粉丝点击