Codeforces869C The Intriguing Obsession

79 篇文章 0 订阅
45 篇文章 0 订阅

标签:数学

— This is not playing but duty as allies ofjustice, Nii-chan!

— Not allies but justice itself, Onii-chan!

With hands joined, go everywhere at a speedfaster than our thoughts! This time, the Fire Sisters — Karen andTsukihi — 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, band c distinct islands respectively.

Bridges have been built between some(possibly all or none) of the islands. A bridge bidirectionally connects twodifferent 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 theshortest distance between them is at least 3, apparently in order to preventoddities 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 thenumber of different ways to build all bridges under the constraints, and givethe answer modulo 998 244 353. Two ways areconsidered different if a pair of islands exist, such that there's a bridgebetween them in one of them, but not in the other.

Input

The first and only line of input containsthree space-separated integers a, b and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in thered, blue and purple clusters, respectively.

Output

Output one line containing aninteger — 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 bridgesthat can possibly be built, and no setup of bridges violates the restrictions.Thus the answer is 23 = 8.

In the second example, the upper twostructures in the figure below are instances of valid ones, while the lower twoare invalid due to the blue and purple clusters, respectively.

 

分析:比赛的时候一直认为这题和杨辉三角有关(由于去年NOIP2016D2T1的坑)然后完美gg

正解应该是动规了吧(或者说是递推)

我们可以将a,b,c三个数分成(a,b,1),(a,c,1),(b,c,1)

将上述的三种情况相乘再取模就是最终的答案

而对于任意一种情况a,b

F(a,b)=f(a-1,b-1)*b+f(a-1,b)

 

Code

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define LL unsigned long long
using namespace std;
const int maxn=5006,mod=998244353;
LL a,b,c,f[maxn][maxn],Max=0;

int main()
{
    cin>>a>>b>>c;
    Max=max(a,max(b,c));
	rep(i,0,Max)f[i][0]=1,f[0][i]=1;
	rep(i,1,Max)
	    rep(j,1,Max)
	        f[i][j]=((f[i-1][j-1]*j)%mod+f[i-1][j])%mod;
	cout<<(((f[a][b]*f[b][c])%mod)*f[a][c])%mod<<endl;
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值