Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— 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.
题目大意 有3个群岛,每个群岛中有一些互不相同的岛屿,现在建一些桥,使得同一群岛内的两个岛屿要么不连通要么最短路至少经过3条桥。给定三个群岛包含的岛数,求合法的建桥的方案数。
显然有某个群岛中的某个岛只能连接其他群岛中的一个岛。群岛与群岛之间的建桥互相独立,所以考虑分开计算。
考虑两个群岛之间建立k座桥,那么方案数就是
所以对于两个群岛之间的建桥方案数for一遍就求完了,最后把答案乘起来就行了。
Code
/**
* Codeforces
* Problem#869C
* Accepted
* Time: 30ms
* Memory: 0k
*/
#include <bits/stdc++.h>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std; #define ll long long void exgcd(ll a, ll b, ll& d, ll &x, ll &y) {
if(!b) {
d = a, x = , y = ;
} else {
exgcd(b, a % b, d, y, x);
y -= (a / b) * x;
}
} ll inv(ll a, ll n) {
ll d, x, y;
exgcd(a, n, d, x, y);
return (x < ) ? (x + n) : (x);
} const int moder = ;
int a, b, c; inline void init() {
scanf("%d%d%d", &a, &b, &c);
} long long calc(int x, int y) {
long long rt = ;
long long Px = , Py = ;
for(int i = ; i <= x && i <= y; i++) {
Px = (Px * (x - i + ) % moder) * inv(i, moder) % moder;
Py = (Py * (y - i + )) % moder;
rt = (rt + (Px * Py % moder)) % moder;
}
return rt;
} inline void solve() {
long long ra = calc(a, b);
long long rb = calc(b, c);
long long rc = calc(c, a);
long long res = ((ra * rb) % moder) * rc % moder;
printf(Auto, res);
} int main() {
init();
solve();
return ;
}
Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学的更多相关文章
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation
还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门 Problem - D - Codeforces 题意 n个数字,n ...
- Codeforces Round #771 (Div. 2), problem: (B) Odd Swap Sort
Problem - B - Codeforces 就是给你个序列, 给他整成升序的, 每次操作可以使相邻两个数交换位置, 交换条件是二数之和为奇数 结果只需输出是否可以整成升序的 思路: 需要奇数偶数 ...
- Codeforces Round #306 (Div. 2), problem: (B) Preparing Olympiad【dfs或01枚举】
题意: 给出n个数字,要求在这n个数中选出至少两个数字,使得它们的和在l,r之间,并且最大的与最小的差值要不小于x.n<=15 Problem - 550B - Codeforces 二进制 利 ...
- Codeforces Round #754 (Div. 2), problem: (A) A.M. Deviation泪目 万万没想到狂wa是因为这
Problem - A - Codeforces 题目 题意很简单每次操作可以使得a1 a2 a3任意两个数分别+1 -1 求最后使得a+c-2b绝对值的最小值 BUG就是最后忽略了-2和2这一点 ...
随机推荐
- vue打包后404,webpack配置问题
首先声明这是基于vue2.x的 1. 将其中build的配置项assetsPublicPath进行修改,改为上图-->目的是将资源文件的引入路径,改为相对地址(相对index.html) 2.h ...
- 前端c标签foreach传值给后台
前端c标签foreach传值给后台 <div style="margin-bottom: 10px"> <c:forEach items="${good ...
- ABC3
Sql Server http://www.cnblogs.com/sunxi/p/4600152.html http://blog.csdn.net/dmz1981/article/details/ ...
- django admin 处理文本换行空格
使用 linebreaks filter <p>{{ blogpassage.content|linebreaksbr }}<p>
- 6.Daemon线程
1.如下代码: package com.bawei.multithread; public class Recursive { private static int counter = 0; publ ...
- AssetBoundle加载非预设资源
1.定义一个协程LoadNonObjFromAB IEnumerator LoadNonObjFromAB(string ABURL, GameObject go, string assetName) ...
- BestCoder Round #55 ($)
C 构造一个矩阵,然后采用矩阵快速幂 #include <iostream> #include <algorithm> #include <string.h> #i ...
- arc 093 C – Traveling Plan
题意: 给出横坐标上一系列的点,一个人从0出发按照下标顺序访问每一个点,再回到0点. 问每次如果去掉一个点,那么访问的距离变为多少. 思路: 去掉这个点,那么就减去这个点到上一点到这一点的距离,减去这 ...
- Python 构造一个可接受任意数量参数的函数
为了能让一个函数接受任意数量的位置参数,可以使用一个* 参数 在这个例子中,rest 是由所有其他位置参数组成的元组.然后我们在代码中把它当成了一个序列来进行后续的计算
- python3安装scrapy教程
2.1xm1http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml3. PyOpensslhttps://pypi.python.org/pypi/pyOpen ...