The Intriguing Obsession
1 second
256 megabytes
standard input
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 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 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.
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 one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.
1 1 1
8
1 2 2
63
1 3 5
3264
6 2 9
813023575
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.

//题意:abc代表,三个颜色的岛的数量,现要建桥,要求同色岛间距离至少为3,求有多少种方式建桥
//发现a、b和a、c以及b、c的关系是独立的,可以先只考虑a和b之间连边的方案数:假设a≤b则方案数为Pab=∑ai=0 Cia×Aib,所以答案为PabPbcPac
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LL long long
#define MX 5005 int a, b, c; LL Ast[MX]; LL inv(LL x)
{
LL ret = , n = MOD-;
while (n)
{
if (n%) ret = ret*x%MOD;
x=x*x%MOD;
n/=;
}
return ret;
} LL A(int x,int y)
{
return Ast[x] * inv(Ast[x-y])%MOD;
} LL C(int x,int y)
{
return A(x,y) * inv(Ast[y])%MOD;
} int main()
{
Ast[]=;
for (int i=;i<=;i++)
Ast[i] = Ast[i-]*i%MOD; while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
LL ans = , temp = ;
for (int i=;i<=min(a,b);i++)
temp=(temp+C(a,i)*A(b,i)%MOD)%MOD;
ans=ans*temp%MOD; temp = ;
for (int i=;i<=min(b,c);i++)
temp=(temp+C(b,i)*A(c,i))%MOD;
ans=ans*temp%MOD; temp=;
for (int i=;i<=min(a,c);i++)
temp=(temp+C(a,i)*A(c,i))%MOD;
ans=ans*temp%MOD;
printf("%I64d\n",ans);
}
return ;
}
The Intriguing Obsession的更多相关文章
- 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 ...
- codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得: 1.由于题目中限制了两个相同 ...
- Codeforces 869C The Intriguing Obsession
题意:有三种颜色的岛屿各a,b,c座,你可以在上面建桥.联通的点必须满足以下条件:1.颜色不同.2.颜色相同且联通的两个点之间的最短路径为3 其实之用考虑两种颜色的即可,状态转移方程也不难推出:F[i ...
- Codeforces Round #439 C. The Intriguing Obsession
题意:给你三种不同颜色的点,每种若干(小于5000),在这些点中连线,要求同色的点的最短路大于等于3或者不连通,求有多少种连法. Examples Input 1 1 1 Output 8 Input ...
- CF869C The Intriguing Obsession(组合数学瞎搞,O(n)莫名过)
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)
2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
- Codeforces 869C The Intriguing Obsession:组合数 or dp
题目链接:http://codeforces.com/problemset/problem/869/C 题意: 红色.蓝色.紫色的小岛分别有a,b,c个. 你可以在两个不同的岛之间架桥,桥的长度为1. ...
- 【CF Round 439 C. The Intriguing Obsession】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
随机推荐
- windows内核编程--头文件包括的奇葩的问题
先给解决的方法:假设您觉得您的头文件包括木有问题,请用WDK的build命令编译试试,非常有可能是由于您用了VS 2010 + EASY SYS 环境的问题 使用VS 2010 + EASY SYS ...
- Odoo8在TreeView左上角增加自定义按钮以及通过继承生成自定义的View_Mode
今天有网友在问怎么在TreeView左上角增加一个自定义的按钮,在查询Odoo 自带的模块,发现在purchase_requisition中有使用,并且此模块还应用到了自定义View_Mode的情况, ...
- Android ListView工作原理全然解析,带你从源代码的角度彻底理解
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/44996879 在Android全部经常使用的原生控件其中.使用方法最复杂的应该就是 ...
- windows 2008 R2 x64安装oracle12c报INS-30131
问题描述:Window 2008 R2 x64安装Oracle12c报[INS-30131]执行安装程序验证所需的初始设置失败 解决方法:先在控制面板的“服务”,看SERVER服务是否启动,如果没有启 ...
- HIVE中join、semi join、outer join
补充说明 left outer join where is not null与left semi join的联系与区别:两者均可实现exists in操作,不同的是,前者允许右表的字段在select或 ...
- Nginx负载均衡和LVS负载均衡的比较分析(转)
Nginx负载均衡和LVS负载均衡的比较分析 作者:匿名 来源:ChinaZ源码报导 浏览:1032次 2011-12-6 15:12:27 字号:大 中 小 [摘要]Nginx是一个高性能的 HTT ...
- webpack 环境搭建基础框架
一.安装babel相关 1,安装依赖 cnpm i -D babel-core babel-loader babel-preset-env babel-preset-stage- babel-plug ...
- 自己动手开发更好用的markdown编辑器-06(自动更新)
这里文章都是从个人的github博客直接复制过来的,排版可能有点乱. 原始地址 http://benq.im/2015/05/12/hexomd-06/ 文章目录 1. 自动更新方案 2. 实现 ...
- ZooKeeper_基础知识学习
ZooKeeper是Hadoop的开源子项目(Google Chubby的开源实现),它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.命名服务.分布式同步.组服务等. Zookee ...
- 521. Longest Uncommon Subsequence I【easy】
521. Longest Uncommon Subsequence I[easy] Given a group of two strings, you need to find the longest ...