Figure thirds of mathematics U82394 SZY

Topic background

SZY play-thirds map in hand.

Title Description

SZY have a great dream, and that is to build a bridge for the world. SZY trained to bridges leading technology, she came to the archipelago.

FIG third islands are divided in A, B, C of three parts. She wants to build a bridge between them, she calculated the possible scenarios in the design drawings. But SZY felt too many programs, and then I would ask you to help her. The results of the requested program number modulo 998,244,353.

(Trimap: Let G = (V, E) is an undirected graph, if the vertex V may be partitioned subsets (A, B, C) of three different post, with the shortest and the set of two arbitrary points length not less than 3, called set point G in FIG. a, B, by the third configuration C of FIG.)

Input Format

Row of three integers a, b, c. The number of three portions are A, B, C island.

Output Format

Output a line to indicate the total number of programs.

Sample input and output

Input # 1

1 1 1

Output # 1

8

Input # 2

1 2 2

Output # 2

63

Input # 3

6 2 9

Output # 3

813023575

Description / Tips

For 20% of the data, a, b, c <= 4;

For 50% of the data, a, b, c <= 3000;

To 100% of the data 1 <= a, b, c <= 500000.

answer

First, the easy conclusion: three sets of set a, b, c, each set of two (e.g., a, b) the total of the program get_sum (a, b);

According to the principle of multiplication, the answer is get_sum (a, b) * get_sum (a, c) * get_sum (b, c);

We can discuss the relationship between each of the two sets;

Because the minimum distance of each set of two> = 3, a set of points so that each set can only be connected to one side of the other;

If the DP, then, --MLE ~, consider direct contributions to answer even when i seen edges

C is the number of combinations, A is the number of permutations.

i == 0, ans0 = C(n, 0) * A(m, 0);

i == 1, ans1 = C(n, 1) * A(m, 1);

\ (\ Sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \ sim \)

i == min (n, m), ans_min (n, m) = C (n, min (n, m)) * A (m, min (n, m));

则get_sum(n, m) = ans0 + ans1 + --- + ans_min(n, m);

O (n) pre-factorial, Fermat's little theorem inversing (998,244,353 prime numbers).

On it.

code:

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int mod = 998244353;
int read() {
    int x = 0, f = 1; char ch = getchar();
    while(! isdigit(ch)) f = (ch=='-')?-1:1, ch = getchar();
    while(isdigit(ch)) x = (x<<3)+(x<<1)+(ch^48), ch = getchar();
    return x * f;
}
int t, a, b, c, ans, ans1, ans2, ans3, fac[500005];
LL ksm(LL x, LL y) {
    LL res = 1;
    for( ; y ;x = (LL)x * x % mod, y >>= 1) 
        if(y & 1) res = (LL)res * x % mod;
    return res;
}
int C(int n, int m) { return ((LL)fac[n] * ksm(fac[n-m], mod-2))% mod  * ksm(fac[m], mod-2) % mod; }
int A(int n, int m) { return (LL)fac[n] * ksm(fac[n-m], mod-2) % mod ; }
inline int getsum(int x, int y) {
    int minl = min(x, y), ans = 0;
    for(int i = 0;i <= minl;i ++) 
        (ans += (LL)C(x, i) * A(y, i) % mod) %= mod;
    return ans;
}
int main() {
    fac[0] = fac[1] = 1;
    for(int i = 2;i <= 500000;i ++) fac[i] = (LL)fac[i-1] * i % mod;
    a = read(); b = read(); c = read();
    ans1 = getsum(a, b);
    ans2 = getsum(b, c);
    ans3 = getsum(a, c);
    ans = (((LL)ans1 * ans2) % mod) * ans3 % mod;
    printf("%d\n", ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/Paranoid-LS/p/11330847.html