C - The Intriguing Obsession CodeForces - 869C 题解( 数学/dp )

13 篇文章 0 订阅
12 篇文章 0 订阅

C - The Intriguing Obsession

  CodeForces - 869C 

— 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
 
 

有三堆颜色分别为红黄蓝三色的岛屿,架桥,一个桥的距离为1.

要求:同色之间不能直接相连或者距离小于3,这句话的意思就是架桥的两个端点只能在不同的颜色之间选,且A堆中任一一个点只能同时和一个B中的点连,这样才能保证B集合中的点之间的距离小于3。

这样看,选择两堆来架桥,最多只能架 两堆中岛屿数量较小的那个集合的总数 座桥,最少可以不架桥,这都符合题目的要求。

接下来就是选择的问题了,假设要在A集合(总数为a) 和 B集合(总数为b)间架k座桥:在a中选k个点,有C(a取k)种情况,在b中选k个点,有C(b取k)种情况,两个集合里各选出k个点,第一个点可以有k种选择,在第一个点选过后,第二个点有k-1种选择……一直到最后一个点有一种选择,哎选完点之后,最后还要乘上k的阶乘。

注意这里k最多只能取到两个集合中小的那个,所以在循环之前先排个序,设定循环上限为小的那个。  

C(n,m)=C(n,n-m)=C(n-1,m-1)+C(n-1,m)

#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const ll mod =998244353;
ll max1,max2,max3;
ll C[5007][5007];
ll  tt[3];
ll jc[5007];
void maxn(ll a,ll b,ll c)//排序
{
    tt[0]=a;
    tt[1]=b;
    tt[2]=c;
    sort(tt,tt+3);
    max3=tt[0];
    max2=tt[1];
    max1=tt[2];
}

ll f(ll a,ll b)//计算
{
    ll res=0;
    for(int i=0;i<=b;i++)
    {
        res+=(C[a][i]*C[b][i]%mod)*(jc[i]%mod);
        res%=mod;
    }
    return res;
}

int main()
{
    for(int i=0;i<=5005;i++)//预处理
    {
        C[i][i]=1;
        C[i][0]=1;
        for(int j=1;j<=i;j++)
        {
            C[i][j]=C[i-1][j]+C[i-1][j-1];
            C[i][j]%=mod;
        }
    }

    jc[0]=1;
    for(int i=1;i<=5005;i++)
    {
        jc[i]=jc[i-1]*i;
        jc[i]%=mod;
    }

    ll res;
    ll res1=0,res2=0,res3=0;
    int a,b,c;
    cin>>a>>b>>c;
    maxn(a,b,c);

    res1=f(max1,max2);
    res2=f(max1,max3);
    res3=f(max2,max3);
    res=(((res1*res2)%mod)*res3)%mod;

    //cout<<res1<<res2<<res3<<endl;
    cout<<res<<endl;


    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值