Codeforces Round #439 (Div. 2) C. The Intriguing Obsession

C. The Intriguing Obsession

Problem Statement

    — 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

Example 1
    Input
        1 1 1
    Output
        8
Example 2
    Input
        1 2 2
    Output
        63
Example 3
    Input
        1 3 5
    Output
        3264
Example 4
    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个小岛组成,要求有多少种造桥方案,使得任意两个位于相同群岛的小岛的最短路不小于3,方案数模998244353输出。

思路

    这题刚开始我被卡了好久qwq..其实……就是一个裸DP.对于3个群岛,我们分别考虑每两个群岛之间不与第三个群岛造桥的方案数,即第一个群岛与第二个群岛之间的造桥方案,第一个群岛与第三个群岛之间的造桥方案,第三个群岛与第二个群岛之间的造桥方案,最后把他们乘起来就好了,复杂度O(5000*5000),dp完后ans=f[a][b]*f[a][c]%mod*f[b][c]%mod。
    dp的转移方程其实挺好想的,我们每次加入一个岛时,我们可以选择与另一个群岛上的一个岛造桥,或者选择不造,就可以很快想到,f[i][j]=f[i-1][j]+f[i-1][j-1]*j,初始状态是f[i][1]=f[1][i]=i+1(1≤i≤5000易得)。

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;
}
inline void readLong(ll &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;
}
/*================Header Template==============*/
const ll mod=998244353;
ll a,b,c,f[5001][5001];
int main() {
    readLong(a);
    readLong(b);
    readLong(c);
    for(int i=1;i<=5000;i++)
        f[i][1]=f[1][i]=i+1;
    for(int i=2;i<=5000;i++) {
        for(int j=2;j<=5000;j++) {
            f[i][j]=f[i-1][j]+f[i-1][j-1]*j%mod;
            f[i][j]%=mod;
        }
    }
    ll ans=f[a][b]*f[a][c]%mod*f[b][c]%mod;
    printf("%lld\n",ans);
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值