CodeForces - 869C The Intriguing Obsession(组合数)
题意:有三个集合,分别含有a、b、c个点,要求给这些点连线,也可以全都不连,每两点距离为1,在同一集合的两点最短距离至少为3的条件下,问有多少种连接方案。
分析:
1、先研究两个集合,若每两个集合都保证满足条件,那最后结果一定满足条件。
2、两个集合间若要最短距离至少为3,那每个集合中的点只能同时与另一个集合中的一个点相连。
假设两个集合间需要连k条线,则可以在集合A中选k个点,在集合B中选k个点,共有k!种连接方式,即C[A][k] * C[B][k] * k!。
两个集合间最少可连0条,最多可连min(A,B),因此k的范围为0~min(A,B)。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const LL MOD = 998244353;
const double pi = acos(-1.0);
const int MAXN = 5000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
LL C[MAXN][MAXN];
LL mul[MAXN];
void init(){
for(int i = 1; i <= 5000; ++i){
C[i][0] = C[i][i] = 1;
for(int j = 1; j < i; ++j){
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
}
}
mul[0] = 1;
for(int i = 1; i <= 5000; ++i){
mul[i] = (mul[i - 1] * i) % MOD;
}
}
LL solve(int x, int y){
int tmp = min(x, y);
LL ans = 0;
for(int i = 0; i <= tmp; ++i){
(ans += (((C[x][i] * C[y][i]) % MOD) * mul[i]) % MOD) %= MOD;
}
return ans;
}
int main(){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
init();
if(a < b) swap(a, b);
if(a < c) swap(a, c);
if(b < c) swap(b, c);
printf("%lld\n", (((solve(a, b) * solve(a, c)) % MOD) * solve(b, c)) % MOD);
return 0;
}
CodeForces - 869C The Intriguing Obsession(组合数)的更多相关文章
- 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 869C The Intriguing Obsession:组合数 or dp
题目链接:http://codeforces.com/problemset/problem/869/C 题意: 红色.蓝色.紫色的小岛分别有a,b,c个. 你可以在两个不同的岛之间架桥,桥的长度为1. ...
- Codeforces 869C The Intriguing Obsession
题意:有三种颜色的岛屿各a,b,c座,你可以在上面建桥.联通的点必须满足以下条件:1.颜色不同.2.颜色相同且联通的两个点之间的最短路径为3 其实之用考虑两种颜色的即可,状态转移方程也不难推出:F[i ...
- cf 869c The Intriguing Obsession
题意:有三种三色的岛,用a,b,c来标识这三种岛.然后规定,同种颜色的岛不能相连,而且同种颜色的岛不能和同一个其他颜色的岛相连.问有多少种建桥的方法. 题解:em....dp.我们先看两个岛之间怎么个 ...
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得: 1.由于题目中限制了两个相同 ...
- 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)
2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少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 ...
- The Intriguing Obsession
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 869 C The Intriguing Obsession
题目描述 — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, ...
随机推荐
- 详解python的数字类型变量与其方法
以下内容引自:https://www.jb51.net/article/97752.htm python数据类型是不允许改变的,这就意味着如果改变 Number 数据类型的值,将重新分配内存空间.下面 ...
- VB.NET中Sub和Function的区别
function是函数,sub是子程序,都可以传递参数,但函数有返回值,子程序没有 function 可以用自身名字返回一个值,sub 需定义别的变量,用传址方式传回值. Sub 过程与Functio ...
- spark实验(一)--linux系统常见命令及其文件互传(2)
2.使用 Linux 系统的常用命令 启动 Linux 虚拟机,进入 Linux 系统,通过查阅相关 Linux 书籍和网络资料,或者参考 本教程官网的“实验指南”的“Linux 系统常用命令”,完成 ...
- Linux系统的发展历史和学习前景介绍
2020年了,我想来跟大家聊聊Linux运维这一行业,从几个方面说下行业的现状.如何学好Linux和如何成为专业运维人员以及云服务对于Linux运维的影响. 一.linux行业状况 我们都知道从199 ...
- JDK各个版本的新特性jdk1.5-jdk8(转)
原文:http://www.cnblogs.com/langtianya/p/3757993.html JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要 ...
- python学习 —— python3简单使用pymysql包操作数据库
python3只支持pymysql(cpython >= 2.6 or >= 3.3,mysql >= 4.1),python2支持mysqldb. 两个例子: import pym ...
- luogu P3356 火星探险问题
本题很简单的费用流问题,有石头的点需要限制,那我们就可以拆点,capacity为1就可以限制,然后cost为-1,直接跑板子就可以了,注意输出的时候找残量网络的反向边
- ubuntu 解压命令全览
.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...
- Hive的存储和MapReduce处理——数据清洗
日期:2019.11.13 博客期:115 星期三 Result文件数据说明: Ip:106.39.41.166,(城市) Date:10/Nov/2016:00:01:02 +0800,(日期) D ...
- 字符串NSString与NSMutableString常用方法
NSString 1.初始化 NSString *str1 = @"a OC Program"; 2.初始化 NSString *str2 = [[NSString alloc] ...