code forces 439 C. 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 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.
/*
* @Author: LyuC
* @Date: 2017-10-06 21:23:13
* @Last Modified by: LyuC
* @Last Modified time: 2017-10-06 23:34:22
*/
#include <bits/stdc++.h> #define LL unsigned long long
#define MOD 998244353
#define N 5005
using namespace std; LL a,b,c;
LL ab,ac,bc;
LL mi,ma; //O(n)的算法
LL F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘
void init(){
inv[] = ;
for(int i = ; i < N; i ++){
inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
}
F[] = Finv[] = ;
for(int i = ; i < N; i ++){
F[i] = F[i-] * 1ll * i % MOD;
Finv[i] = Finv[i-] * 1ll * inv[i] % MOD;
}
}
LL Comb(LL n, LL m){//comb(n, m)就是C(n, m)
if(m < || m > n) return ;
return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;
} int main(){
// freopen("in.txt","r",stdin);
init();
ab=;
ac=;
bc=;
cin>>a>>b>>c;
//ab;
mi=min(a,b);
ma=max(a,b);
for(int i=;i<=mi;i++){
ab=(ab+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;
}
//ac;
mi=min(a,c);
ma=max(a,c);
for(int i=;i<=mi;i++){
ac=(ac+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;
}
//bc;
mi=min(b,c);
ma=max(b,c);
for(int i=;i<=mi;i++){
bc=(bc+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;
}
cout<<ab*ac%MOD*bc%MOD<<endl;
return ;
}
code forces 439 C. The Intriguing Obsession的更多相关文章
- Codeforces Round #439 C. The Intriguing Obsession
题意:给你三种不同颜色的点,每种若干(小于5000),在这些点中连线,要求同色的点的最短路大于等于3或者不连通,求有多少种连法. Examples Input 1 1 1 Output 8 Input ...
- 【CF Round 439 C. The Intriguing Obsession】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得: 1.由于题目中限制了两个相同 ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- The Intriguing Obsession
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)
2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
随机推荐
- 业余草通告CSDN博客用户zhang__ao非法转载文章的公告
今天早上有粉丝给我反馈,CSDN的一位用户大量非法的转载了我的个人网站:业余草(www.xttblog.com)上的大量文章.现一对该用户转载业余草上网站上的所有文章进行了举报! 从上图中可以看出,该 ...
- JS中关于数组的内容
前 言 LIUWE 在网站制作过程中,数组可以说是起着举足轻重的地位.今天就给大家介绍一下数组的一些相关内容.例如:如何声明一个数组和在网站制作过程中我们常用的一些数组的方法.介绍的不好还请多多 ...
- angular-bootstrap ui-date组件问题总结
使用angular框架的时候,之前用的时间控件是引入My97DatePicker组件实现的,但是因为 1.My97DatePicker样式不太好看以及偶尔会出现底部被遮盖的情况.点击不可编辑input ...
- java集合系列——java集合概述(一)
在JDK中集合是很重要的,学习java那么一定要好好的去了解一下集合的源码以及一些集合实现的思想! 一:集合的UML类图(网上下载的图片) Java集合工具包位置是java.util.* 二:集合工具 ...
- 实例讲解webpack的基本使用第四篇
这一篇来讲解一下webpack的loader的使用,用webpack打包文件,css,img,icon等都需要下载安装对应的loader文件,并且写好配置项,才可以进行打包,废话不多说,直接开始实战. ...
- SpringBoot初体验
1.elipse中创建Springboot项目并启动 具体创建步骤请参考:Eclipse中创建新的Spring Boot项目 2.项目的属性配置 a.首先我们在项目的resources目录下appli ...
- Centos 7.4 下初探Zabbix安装
工作一波停一波起,感觉离开.net好久了. 最近工作中发现服务器监视都是用了zabbix,对于我这类不懂的狠狠弥补了一下知识. 无意发现zabbix带有api,就想开发个工具调用api来着.可是api ...
- vue2购物车ch2-(商品列表显示)
1 index.html <!DOCTYPE html><html lang="en"><head> <meta charset=&quo ...
- ubuntu系统如何屏幕截图
我们知道,windows下有很多截图的软件和插件,那么在ubuntu系统下我们该怎样截图呢? 下面就让小编来告诉你几种简单的方法吧. 工具/原料 ubuntu系统电脑 方法一: 1.也许很多朋友都知道 ...
- wpf 制作必输项的*标记
直接引用帮助文档上的话吧,以免下次忘记! AdornedElementPlaceholder 类 .NET Framework 3.5 其他版本 此主题尚未评级 - 评价此主题 更新:20 ...