题目描述

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

输入输出格式

输入格式:

The first and only line of input contains three space-separated integers aa , bb and cc ( 1<=a,b,c<=5000 ) — the number of islands in the red, blue and purple clusters, respectively.

输出格式:

Output one line containing an integer — the number of different ways to build bridges, modulo 998244353.

输入输出样例

输入样例#1:

1 1 1
输出样例#1:

8
输入样例#2:

1 2 2
输出样例#2:

63
输入样例#3:

1 3 5
输出样例#3:

3264
输入样例#4:

6 2 9
输出样例#4:

813023575

说明

In the first example, there are 33 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2^{3}=823=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,所以同色岛之间不能有边并且一个岛不能连两个同色岛。

于是我们可以分别求一下2色到1色的方案数,3色到1色的方案数,3色到2色的方案数,然后把它们乘起来就好啦。

求一个搭配的方案数要用一下组合数。。。。

#include<bits/stdc++.h>
#define ll long long
#define maxn 5005
const int ha=998244353;
using namespace std;
int jc[maxn],ni[maxn];
int ans=0,a,b,c; inline int ksm(int x,int y){
int an=1;
for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
return an;
} inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline void init(){
jc[0]=1;
for(int i=1;i<=5000;i++) jc[i]=jc[i-1]*(ll)i%ha;
ni[5000]=ksm(jc[5000],ha-2);
for(int i=5000;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
} inline int P(int x,int y){
return x<y?0:jc[x]*(ll)ni[x-y]%ha;
} inline int C(int x,int y){
return x<y?0:P(x,y)*(ll)ni[y]%ha;
} int main(){
init();
cin>>a>>b>>c;
for(int i=0;i<=b;i++) ans=add(ans,C(b,i)*(ll)P(a,b-i)%ha);
int an[2];
an[0]=an[1]=0;
for(int i=0;i<=c;i++){
an[0]=add(an[0],C(c,i)*(ll)P(a,c-i)%ha);
an[1]=add(an[1],C(c,i)*(ll)P(b,c-i)%ha);
} ans=ans*(ll)an[0]%ha*(ll)an[1]%ha; printf("%d\n",ans);
return 0;
}

  

Codeforces 869 C The Intriguing Obsession的更多相关文章

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

    C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得:     1.由于题目中限制了两个相同 ...

  2. codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. code forces 439 C. The Intriguing Obsession

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. The Intriguing Obsession

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

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

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

  6. 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)

    2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...

  7. Codeforces 869C The Intriguing Obsession

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

  8. Codeforces Round #439 C. The Intriguing Obsession

    题意:给你三种不同颜色的点,每种若干(小于5000),在这些点中连线,要求同色的点的最短路大于等于3或者不连通,求有多少种连法. Examples Input 1 1 1 Output 8 Input ...

  9. Codeforces Round #439 (Div. 2)C - The Intriguing Obsession(简单dp)

    传送门 题意 给出三个集合,每个集合的元素数量为a,b,c,现在需要连边,满足集合内元素不可达或最短路为3,求可行方案数 分析 设dp[i][j]为a集合元素为i个,b集合元素为j个的可行方案,易知( ...

随机推荐

  1. Sicily 8843 Ranking and Friendship

    http://soj.me/8843 题意:几个人想做好朋友,朋友之间相差位置小于等于k,且长度相同分析:排序,将长度相同的放在一起.若长度相同,第i个人能放进去的条件是位置相差下雨等于k.      ...

  2. OpenCV学习笔记(七) 图像金字塔 阈值 边界

    转自: OpenCV 教程 使用 图像金字塔 进行缩放 图像金字塔是视觉运用中广泛采用的一项技术.一个图像金字塔是一系列图像的集合 - 所有图像来源于同一张原始图像 - 通过梯次向下采样获得,直到达到 ...

  3. MySQL之索引(四)

    压缩索引 MyISAM使用前缀压缩来减少索引的大小,从而让更多的索引可以放入内存中,这在某些情况下能极大地提高性能.默认只压缩字符串,但通过参数设置也可以对整数做压缩. MyISAM压缩每个索引块的方 ...

  4. Docker与CTF

    Docker与CTF 主要是用来搭建环境,漏洞环境,CTF比赛题目复现. docker你可以把它理解为一个vmware. iamges:vmware需要的iso镜像 container:vmware运 ...

  5. Python常见数据类型及操作

    基础数据类型 什么是数据类型? 我们人类可以很容易的分清数字与字符的区别,但计算机并不能,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,“汉”是文字,否则它是分不清1和‘汉’ ...

  6. selenium定位下拉菜单好文

    http://www.cnblogs.com/nbkhic/archive/2011/10/23/2221726.html 定位下拉菜单

  7. c#每循环100次提交一次数据,最后一次不足100次提交一次

    StringBuilder sb=new StringBuilder(); string strId=dataGridView1.Rows[dataGridView1.CurrentRow.Index ...

  8. 流浪者(rover)

    流浪者(rover) 题目描述 有一位流浪者正在一个n∗mn∗m的网格图上流浪.初始时流浪者拥有SS点体力值. 流浪者会从(1,1)(1,1)走向(n,m)(n,m),并且他只会向下走((x,y)→( ...

  9. 基于深度摄像头的障碍物检测(realsense+opencv)

    前几天老大给了个任务,让我帮slam组写一个基于深度摄像头的障碍物检测,捣鼓了两天弄出来了,效果还不错,就在这里记一下了. 代码的核心思路是首先通过二值化,将一米之外的安全距离置零不考虑,然后通过开运 ...

  10. mrpt安装

    1.mrpt2.0参 See PPA for mrpt 2.0 branch (for mrpt 1.5.* read here). sudo add-apt-repository ppa:josel ...