题意:有三个集合,分别含有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(组合数)的更多相关文章

  1. codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. Codeforces 869C The Intriguing Obsession:组合数 or dp

    题目链接:http://codeforces.com/problemset/problem/869/C 题意: 红色.蓝色.紫色的小岛分别有a,b,c个. 你可以在两个不同的岛之间架桥,桥的长度为1. ...

  3. Codeforces 869C The Intriguing Obsession

    题意:有三种颜色的岛屿各a,b,c座,你可以在上面建桥.联通的点必须满足以下条件:1.颜色不同.2.颜色相同且联通的两个点之间的最短路径为3 其实之用考虑两种颜色的即可,状态转移方程也不难推出:F[i ...

  4. cf 869c The Intriguing Obsession

    题意:有三种三色的岛,用a,b,c来标识这三种岛.然后规定,同种颜色的岛不能相连,而且同种颜色的岛不能和同一个其他颜色的岛相连.问有多少种建桥的方法. 题解:em....dp.我们先看两个岛之间怎么个 ...

  5. Codeforces Round #439 (Div. 2) C. The Intriguing Obsession

    C. The Intriguing Obsession 题目链接http://codeforces.com/contest/869/problem/C 解题心得:     1.由于题目中限制了两个相同 ...

  6. 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)

    2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...

  7. 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 ...

  8. The Intriguing Obsession

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. Codeforces 869 C The Intriguing Obsession

    题目描述 — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, ...

随机推荐

  1. nodejs的POST两种type类型提交(原生)

    POST数据的两种提交格式 application/x-www-form-urlencoded(上传数据中没有文件) multipart/form-data (文件上传) 获取POST数据,post数 ...

  2. 前端学习 之 CSS(一)

    一:什么是 CSS? ·CSS 指层叠样式表 (Cascading Style Sheets) ·样式定义如何显示 HTML 元素 ·样式通常存储在样式表中 ·把样式添加到 HTML 4.0 中,是为 ...

  3. C语言笔记 12_可变参数&内存管理&命令行参数

    可变参数 有时,您可能会碰到这样的情况,您希望函数带有可变数量的参数,而不是预定义数量的参数.C 语言为这种情况提供了一个解决方案,它允许您定义一个函数,能根据具体的需求接受可变数量的参数.下面的实例 ...

  4. vue学习笔记:Hello Vue

    编写简单例子,了解下基本语法 <!DOCTYPE html> <html> <head> <meta charset="utf-8 "&g ...

  5. 六 Struts2访问Servlet的API方式一:完全解耦合的方式

    注意: 完全解耦合的方式,这种方式只能获得代表request.session.application的数据的Map集合. 不能操作这些对象的本身的方法. 1 jsp: <%@ page lang ...

  6. Java基础 -4.4

    For循环 for循环也是一种常规的使用结构 public static void main(String[] args) { for(定义循环的初始值;循环判断;修改循环条件) { 循环语句的执行; ...

  7. Java源码-集合-LinkedList

    基于JDK1.8.0_191 介绍   LinkedList是以节点来保存数据的,不像数组在创建的时候需要申请一段连续的空间,LinkedList里的数据是可以存放在不同的空间当中,然后以内存地址作为 ...

  8. 寒假所做事情日志-Office重新激活

    日期:2020.01.18 博客期:127 星期六 好吧,今天出了一趟远门,将近傍晚才回来.任务目标其实相当于什么也没做,但回来发现Office居然过期了,老师给的那些文件居然无法修改了,于是乎剩下的 ...

  9. 神奇的navigationBar.translucent

    初步实践所得: 当translucent属性为YES的时候,vc的view的坐标从导航栏的左上角开始: 当translucent属性为NO的时候,vc的view的坐标从导航栏的左下角开始:   深入探 ...

  10. 微信小程序 画布arc截取圆形图片

    画布提供了一种可以创建圆的方法 arc(x, y, r, s, e, counterclockwise) x,y:圆心 r:圆的半径 s:起始弧度 (0) e:终止弧度 (1.5 * Math.PI) ...