zoukankan      html  css  js  c++  java
  • code forces 439 C. 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 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 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 is 23 = 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.

    /*
    * @Author: LyuC
    * @Date:   2017-10-06 21:23:13
    * @Last Modified by:   LyuC
    * @Last Modified time: 2017-10-06 23:34:22
    */
    #include <bits/stdc++.h>
    
    #define LL unsigned long long 
    #define MOD 998244353
    #define N 5005
    using namespace std;
    
    LL a,b,c;
    LL ab,ac,bc;
    LL mi,ma;
    
    //O(n)的算法
    LL F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘 
    void init(){
        inv[1] = 1;
        for(int i = 2; i < N; i ++){
            inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
        }
        F[0] = Finv[0] = 1;
        for(int i = 1; i < N; i ++){
            F[i] = F[i-1] * 1ll * i % MOD;
            Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD;
        }
    }
    LL Comb(LL n, LL m){//comb(n, m)就是C(n, m) 
        if(m < 0 || m > n) return 0;
        return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;
    }
    
    int main(){
        // freopen("in.txt","r",stdin);
        init();
        ab=0;
        ac=0;
        bc=0;
        cin>>a>>b>>c;
        //ab;
        mi=min(a,b);
        ma=max(a,b);
        for(int i=0;i<=mi;i++){
            ab=(ab+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;
        }
        //ac;
        mi=min(a,c);
        ma=max(a,c);
        for(int i=0;i<=mi;i++){
            ac=(ac+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;
        }
        //bc;
        mi=min(b,c);
        ma=max(b,c);
        for(int i=0;i<=mi;i++){
            bc=(bc+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;
        }
        cout<<ab*ac%MOD*bc%MOD<<endl;
        return 0;
    }
  • 相关阅读:
    gin使用validator库参数校验若干实用技巧
    在gin框架中使用JWT
    使用zap接收gin框架默认的日志并配置日志归档
    gin框架路由拆分与注册
    Gin框架介绍及使用
    GO学习-(39) 优雅地关机或重启
    GO学习-(38) Go语言结构体转map[string]interface{}的若干方法
    WPF中不规则窗体与WindowsFormsHost控件的兼容问题完美解决方案
    [ 夜间模式 ] NightVersion
    HDU1518 Square(DFS)
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/7634827.html
Copyright © 2011-2022 走看看