zoukankan      html  css  js  c++  java
  • 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.

    题意:有三种三色的岛,用a,b,c来标识这三种岛。然后规定,同种颜色的岛不能相连,而且同种颜色的岛不能和同一个其他颜色的岛相连。问有多少种建桥的方法。

    我个人感觉挺难想到的,毕竟我还太菜。

    看了大牛的代码,理解之后再写了一份。

    dp其实在这里挺好用的,只是状态转移方程挺难找的。

     1 #include <iostream>
     2 #define ll long long int
     3 #define N 5005
     4 #define Max 998244353
     5 using namespace std;
     6 ll dp[N][N];
     7 ll ans=1;
     8 int a,b,c;
     9 int main(){
    10   cin>>a>>b>>c;
    11   int n=max(a,max(b,c));
    12   for(int i=1;i<=n;i++){
    13     dp[i][1]=i+1;
    14     dp[1][i]=i+1;
    15   }
    16   for(int i=2;i<=n;i++){
    17     for(int j=2;j<=n;j++){
    18       dp[i][j]=(i*dp[i-1][j-1]+dp[i][j-1])%Max;
    19     }
    20   }
    21   ans=dp[a][b]*ans%Max;
    22   ans=dp[a][c]*ans%Max;
    23   ans=dp[b][c]*ans%Max;
    24   cout<<ans%Max<<endl;
    25   return 0;
    26 }

     

  • 相关阅读:
    [AS3]AMF3+JAVA的调用范例
    SmartFoxServer,多人flash游戏开发
    Flex2 发现之旅:在Flex中嵌入完整HTML页面
    让.Net 程序脱离.net framework框架运行
    ASP.NET 数据列表控件的分页总结
    中国移动飞信免费发短信API接口(第三方 Fetion API)[原创]
    Ubuntu下安装wine详细介绍
    SQL SERVER 2008 R2 序列号大全
    linux 下安装ATI 显卡驱动
    jdk 环境变量设置
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7647750.html
Copyright © 2011-2022 走看看