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 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 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 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
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.

【题意】:给出三种颜色岛屿的数量,问有多少种建桥方法。限制是:对于相同颜色的岛屿,要么不能直接相连,要么最少相距为3。

【分析】:知识清单:http://blog.csdn.net/sr_19930829/article/details/40888349

dp的转移方程其实挺好想的,我们每次加入一个岛时,我们可以选择与另一个群岛上的一个岛造桥,或者选择不造,就可以很快想到,f[i][j] = f[i-1][j]+f[i-1][j-1]*j,初始状态是f[0][1]=f[0][i]=1(1≤i≤5000易得)。

对于3个群岛,我们分别考虑每两个群岛之间不与第三个群岛造桥的方案数,即第一个群岛与第二个群岛之间的造桥方案,第一个群岛与第三个群岛之间的造桥方案,第三个群岛与第二个群岛之间的造桥方案,最后把他们乘起来就好了,复杂度O(5000*5000),dp完后ans=f[a][b]*f[a][c]%mod*f[b][c]%mod。


由于同岛群的任意两岛最短距离至少为 3 或不能有路径。则可知,非法路径的连接方案为:

  • 同岛群两岛直接连接。
  • 同岛群两岛均与另一岛群的某岛连接。

故反向条件为:任意两岛群之间取任意 k (岛群数岛群数k∈[0,min(岛群数1,岛群数2)]) 个点,两两建桥均为合法。三个岛群的总方案数即认为是 (a岛群, b岛群) * (a岛群, c岛群) * (b岛群, c岛群) 。

【代码】:

//327ms/1s
#include<bits/stdc++.h>
using namespace std;
const int base = , nmax=;
typedef long long ll;
ll f[nmax][nmax]; int main()
{
for (int i=;i<nmax;++i)
for (int j=;j<nmax;++j)
f[i][j]=(i==||j==)?:(f[i][j-]+i*f[i-][j-])%base; int a,b,c;
cin>>a>>b>>c;
cout<<f[a][b]*f[b][c]%base*f[c][a]%base;
}

codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】的更多相关文章

  1. Codeforces 869C The Intriguing Obsession:组合数 or dp

    题目链接:http://codeforces.com/problemset/problem/869/C 题意: 红色.蓝色.紫色的小岛分别有a,b,c个. 你可以在两个不同的岛之间架桥,桥的长度为1. ...

  2. Codeforces 869C The Intriguing Obsession

    题意:有三种颜色的岛屿各a,b,c座,你可以在上面建桥.联通的点必须满足以下条件:1.颜色不同.2.颜色相同且联通的两个点之间的最短路径为3 其实之用考虑两种颜色的即可,状态转移方程也不难推出:F[i ...

  3. CodeForces - 869C The Intriguing Obsession(组合数)

    题意:有三个集合,分别含有a.b.c个点,要求给这些点连线,也可以全都不连,每两点距离为1,在同一集合的两点最短距离至少为3的条件下,问有多少种连接方案. 分析: 1.先研究两个集合,若每两个集合都保 ...

  4. Codeforces Round #100 E. New Year Garland (第二类斯特林数+dp)

    题目链接: http://codeforces.com/problemset/problem/140/E 题意: 圣诞树上挂彩球,要求从上到下挂\(n\)层彩球.已知有\(m\)种颜色的球,球的数量不 ...

  5. 【hdu4045】Machine scheduling(dp+第二类斯特林数)

    传送门 题意: 从\(n\)个人中选\(r\)个出来,但每两个人的标号不能少于\(k\). 再将\(r\)个人分为不超过\(m\)个集合. 问有多少种方案. 思路: 直接\(dp\)预处理出从\(n\ ...

  6. codeforces 659 G. Fence Divercity 组合数学 dp

    http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代 ...

  7. cf 869c The Intriguing Obsession

    题意:有三种三色的岛,用a,b,c来标识这三种岛.然后规定,同种颜色的岛不能相连,而且同种颜色的岛不能和同一个其他颜色的岛相连.问有多少种建桥的方法. 题解:em....dp.我们先看两个岛之间怎么个 ...

  8. CF869C The Intriguing Obsession(组合数学瞎搞,O(n)莫名过)

    — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...

  9. BZOJ 2159: Crash 的文明世界(树形dp+第二类斯特林数+组合数)

    题意 给定一棵 \(n\) 个点的树和一个常数 \(k\) , 对于每个 \(i\) , 求 \[\displaystyle S(i) = \sum _{j=1} ^ {n} \mathrm{dist ...

随机推荐

  1. Impala-1

    Impala相关操作上   阅读目录 序 数据库相关 表相关 系列索引 序 上一篇,我们介绍Impala的介绍及安装.   下面我们开始继续进一步的了解Impala的相关操作. 数据库相关 一:创建 ...

  2. jloi2017(shoi2017?)六省联考酱油记

    Day -n 听说了4.22.4.23的省选,而且还是六省联考. 压力山大. 尽管我只是一名高一的simple OIer,在省选到来之前,心里还是很紧张的. 毕竟自己也知道南方dalao们都是神犇,像 ...

  3. Phaser的timer用法

    1. 延迟timer,相当于setTimeout game.time.events.add(Phaser.Timer.SECOND*5,this.delayOver,this); 2. 循环timer ...

  4. 【BZOJ 4514】[Sdoi2016]数字配对 费用流

    利用spfa流的性质,我直接拆两半,正解分奇偶(妙),而且判断是否整除且质数我用的是暴力根号,整洁判断质数个数差一(其他非spfa流怎么做?) #include <cstdio> #inc ...

  5. JQuery用鼠标选文字来发新浪微博

    最近注意到新浪博客有个小功能,就是当鼠标选中一段文字时会浮现一个小图片,点击这个图片可以把选中内容发送到新浪微博,一时兴起昨晚就写了一个Demo玩了一下,代码超简单,没优化,有兴趣的朋友可以自己改进. ...

  6. SQL SERVER:删除筛选记录中前100条数据

    delete from table1 where id in (select top 100 id from table1)

  7. HDU1054 Strategic Game(最小点覆盖)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. cloudera manager 5.3完整卸载脚本

    service cloudera-scm-agent stop service cloudera-scm-agent stop umount /var/run/cloudera-scm-agent/p ...

  9. BZOJ 4527: K-D-Sequence

    4527: K-D-Sequence Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 163  Solved: 66[Submit][Status][D ...

  10. 【BZOJ2648】SJY摆棋子 [KD-tree]

    SJY摆棋子 Time Limit: 20 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 这天,SJY显得无聊.在家自己 ...