Codeforces-869 C. The Intriguing Obsession [组合数学]

The Intriguing Obsession

time limit per test 1 second

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 3 5

Output

3264
明显的一道组合题,推(cai)了好久的公式都不对。索性挂机了。
看了别人的思路:
首先只考虑有两种颜色a,b球的情况。显然一个球不能被连接两次,否则距离就会小于3。这样就应该是一个a对应一个b。然后将这种状态看成盒子模型,选择max(a,b)为盒子,min(a,b)作为球。
这样问题就变成了对于每个球可以选择放或者不放,并且放的时候每个盒子保证只能有一个球。那么组合的方式有:

$f(a,b)=sum_{k=0}^{b}C_{b}^{k}C_{a}^{k}k!$

 

同理,每两个颜色相互独立,乘积就是答案。
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL mod = 998244353;
const int maxn = 5010;
LL C[maxn][maxn];
void init() {
    for (int i = 0; i <= 5000; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) C[i][j] = (C[i-1][j-1]+C[i-1][j])%mod;
    }
}
LL f(LL a, LL b) {
    if (a > b) swap(a, b);
    LL res = 1; LL t = 1;
    for (int i = 1; i <= a; i++) {
        t = t*i%mod;
        res = (res + C[a][i]*C[b][i]%mod*t%mod + mod)%mod;
    }
    return res;
}
int main(int argc, char const *argv[])
{
    init();
    LL a, b, c;
    scanf("%I64d%I64d%I64d", &a, &b, &c);
    printf("%I64d
",f(a, b)*f(b, c)%mod*f(a, c)%mod);
    return 0;
}
原文地址:https://www.cnblogs.com/cniwoq/p/7634654.html