codeforces contest 869 problem 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 ofa, b andc 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 length1. 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 isat 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 modulo998 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, modulo998 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 is23 = 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.





题意:

解:选出两个颜色 每次从他的个数中选i个(0=<i<=(min(x,y))) 然后两者相乘 再乘以i的阶乘(两列数组合的方法数)

        之所以选相同的个数 是因为选多了连不上等于不选 而且不能一个颜色同时连两个其他相同的颜色 所以方法数是阶乘 将三组点对之间的所有方法数相乘就是结果



#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long LL;
const LL mod = 998244353;
map<int,int>q;
LL a[N], b[N];
LL quick(LL r,LL n)
{
    LL x=1;
    while(n)
    {
        if(n&1) x=x*r%mod;
        r=r*r%mod;
        n>>=1;
    }
    return x;
}

LL cal(LL x,LL y)
{
    LL ans=0;
    for(LL i=0;i<=x&&i<=y;i++)
    {
        ans=(ans+a[x]*b[i]%mod*b[x-i]%mod*a[y]%mod*b[i]%mod*b[y-i]%mod*a[i])%mod;
    }
    return ans%mod;
}

int main()
{
    a[0]=1,b[0]=1;
    for(LL i=1;i<=5000;i++)
    {
        a[i]=a[i-1]*i%mod;
        b[i]=quick(a[i],mod-2);
    }
    LL x, y, z;
    scanf("%I64d %I64d %I64d", &x, &y, &z);
    LL ans=1;
    ans=ans*cal(x,y)%mod;
    ans=ans*cal(x,z)%mod;
    ans=ans*cal(z,y)%mod;
    cout<<ans%mod<<endl;
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值