• Codeforces Round #439 (Div. 2) C DP(图论)


    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 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.

    思路:可以单独考虑ab,ac,bc间连边的情况,因为三种情况间是无关联的,所以相乘即为答案。

    代码:

     1 #include<bits/stdc++.h>
     2 #define db double
     3 #include<vector>
     4 #define ll long long
     5 #define vec vector<ll>
     6 #define Mt  vector<vec>
     7 #define ci(x) scanf("%d",&x)
     8 #define cd(x) scanf("%lf",&x)
     9 #define cl(x) scanf("%lld",&x)
    10 #define pi(x) printf("%d
    ",x)
    11 #define pd(x) printf("%f
    ",x)
    12 #define pl(x) printf("%lld
    ",x)
    13 const int N = 5e3 + 5;
    14 const int mod = 1e9 + 7;
    15 const int MOD = 998244353;
    16 const db  eps = 1e-18;
    17 const db  PI = acos(-1.0);
    18 using namespace std;
    19 int a[N],b[N];
    20 ll f[N][N];
    21 int main(){
    22     int x,y,z;
    23     for(int i=0;i<N;i++) f[i][0]=f[0][i]=1;
    24     for(int i=1;i<N;i++)
    25         for(int j=1;j<N;j++)
    26         {
    27             f[i][j]=f[i][j-1]%MOD+f[i-1][j-1]*i%MOD;//f[i][j-1]:第j条边不连 f[i-1][j-1]:第j条边连上
    28             f[i][j]%=MOD;
    29         }
    30     ci(x),ci(y),ci(z);
    31     pl(f[x][y]*f[x][z]%MOD*f[y][z]%MOD);
    32 
    33     return 0;
    34 }
  • 相关阅读:
    Linux下的cut选取命令详解
    Linux下的hostname命令详解
    Linux下的sed流编辑器命令详解
    Linux下的设置静态IP命令详解
    模型评估方法
    模型验证方法
    超参数优化方法
    数据集划分方法
    数据预处理:标称型特征的编码和缺失值处理
    数据预处理:规范化(Normalize)和二值化(Binarize)
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/7744033.html
Copyright © 2020-2023  润新知