zoukankan      html  css  js  c++  java
  • C

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

    Example

    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.

    题意:岛屿有三种颜色,每种颜色有a,b,c座,连桥的话,桥长为1,同种颜色之间不能连桥,或者他们之间的距离不能小于3,问有多少种连法?

    参考代码:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int INF=0x3f3f3f3f;
     5 const int SIZE=5010;
     6 const int MOD=998244353;
     7 typedef long long LL;
     8 LL dp[SIZE][SIZE];
     9 int main()
    10 {
    11     LL a,b,c;
    12     scanf("%I64d%I64d%I64d",&a,&b,&c);
    13     LL n=max(a,max(b,c));
    14     
    15     for(int i=0;i<=n;i++)
    16         dp[i][0]=dp[0][i]=1;
    17     ///前面的情况肯定是默认为1 ,方便下面的与前面相乘
    18     
    19     for(int i=1;i<=n;i++)
    20         for(int j=1;j<=n;j++)
    21             dp[i][j]=(dp[i-1][j-1]*i+dp[i][j-1])%MOD;
    22             ///连的话与前面情况相乘+不连
    23             
    24     LL ans=1;
    25     ans=dp[a][b]*ans%MOD; 
    26     ans=dp[a][c]*ans%MOD;
    27     ans=dp[b][c]*ans%MOD;
    28     
    29     ///每两种颜色之间的种类
    30     printf("%I64d
    ",ans);
    31     return 0;
    32 }
    View Code
    まだまだだね
  • 相关阅读:
    hdu 2544 单源最短路问题 dijkstra+堆优化模板
    CImg、libjpeg--介绍、配置(操作JPEG)
    【Android归纳】开发中应该注意的事项
    iOS測试——置换測试: Mock, Stub 和其它
    <html>
    系统吞吐量、TPS(QPS)、用户并发量、性能測试概念和公式
    hdu 1038 Biker&#39;s Trip Odometer(水题)
    java泛型
    从头认识Spring-2.1 自己主动装配(2)-byType(2)
    11.2.0.3 RAC(VCS)节点crash以及hang的问题分析
  • 原文地址:https://www.cnblogs.com/xxQ-1999/p/7993161.html
Copyright © 2011-2022 走看看