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.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
 
随机推荐
- [UIKit学习]03.关于UILable
			
代码创建UILabel UILabel *label = [[UILabel alloc] init]; label.text = @"单肩包"; label.frame = CG ...
 - 修改NSMutableArray中的元素时的注意事项
			
最近做项目遇到从文件加载数组,并对数组中的元素进行操作的问题,特意写了个Demo,记录下要注意的东西: 代码如下: NSArray *array = @["]; NSMutableArray ...
 - JS设计模式(三) 数据访问对象模式
			
引言 HTML5 提供了两种在客户端存储数据的新方法:localStorage.sessionStorage,他们是Web Storage API 提供的两种存储机制,区别在于前者属于永久性存储,而后 ...
 - /MD、/MT、/LD( 使用  多线程版本  运行时库的C runtime library)
			
/MD./MT./LD(使用运行时库)(微软官网解释) Visual C++ 编译器选项 /MD./ML./MT./LD 区别 指定与你项目连接的运行期库 /MT多线程应用程序 /Mtd多线程应用程序 ...
 - Another Easy Problem   fzu1753
			
Another Easy Problem Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u ...
 - 移动WEB 响应式设计 @media总结
			
第一种: 在引用样式的时候添加 <link rel="stylesheet" media="mediatype and|not|only (media featur ...
 - SQLserver2008r2安装过程
			
首先,下载SQLserver2008的安装包,下载完成打开是以下界面 点击开始安装,随着安装进程,点下一步 . 接着来到设置角色的过程,点击SQL功能安装 然后按下一步,来到功能选择,点击" ...
 - Crossin-8-1;8-2课程记录
			
打开文件: open,注意打开文件的路径 读取结束需使用close读取文件: read readlines readline for in 重置光标位置: se ...
 - python random从集合中随机选择元素
			
1.使用python random模块的choice方法随机选择某个元素 from random import choice foo = ['a', 'b', 'c', 'd', 'e'] print ...
 - xml解析总结-常用需掌握
			
Xml文档的解析 XML解析方式分为两种:DOM方式和SAX方式 DOM:Document Object Model, 文档对象模型.这种方式是W3C推荐的处理XML的一种方式. SAX:Simple ...