The Intriguing Obsession

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.

//题意:abc代表,三个颜色的岛的数量,现要建桥,要求同色岛间距离至少为3,求有多少种方式建桥

//发现a、b和a、c以及b、c的关系是独立的,可以先只考虑a和b之间连边的方案数:假设ab则方案数为Pab=ai=0 Cia×Aib,所以答案为PabPbcPac

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define MOD 998244353
 4 #define INF 0x3f3f3f3f
 5 #define LL long long
 6 #define MX 5005
 7 
 8 int a, b, c;
 9 
10 LL Ast[MX];
11 
12 LL inv(LL x)
13 {
14     LL ret = 1, n = MOD-2;
15     while (n)
16     {
17         if (n%2) ret = ret*x%MOD;
18         x=x*x%MOD;
19         n/=2;
20     }
21     return ret;
22 }
23 
24 LL A(int x,int y)
25 {
26     return Ast[x] * inv(Ast[x-y])%MOD;
27 }
28 
29 LL C(int x,int y)
30 {
31     return A(x,y) * inv(Ast[y])%MOD;
32 }
33 
34 int main()
35 {
36     Ast[0]=1;
37     for (int i=1;i<=5000;i++)
38         Ast[i] = Ast[i-1]*i%MOD;
39 
40     while(scanf("%d%d%d",&a,&b,&c)!=EOF)
41     {
42         LL ans = 1, temp = 0;
43         for (int i=0;i<=min(a,b);i++)
44             temp=(temp+C(a,i)*A(b,i)%MOD)%MOD;
45         ans=ans*temp%MOD;
46 
47         temp = 0;
48         for (int i=0;i<=min(b,c);i++)
49             temp=(temp+C(b,i)*A(c,i))%MOD;
50         ans=ans*temp%MOD;
51 
52         temp=0;
53         for (int i=0;i<=min(a,c);i++)
54             temp=(temp+C(a,i)*A(c,i))%MOD;
55         ans=ans*temp%MOD;
56         printf("%I64d
",ans);
57     }
58     return 0;
59 }
View Code
原文地址:https://www.cnblogs.com/haoabcd2010/p/7673669.html