题意:有三个集合,分别含有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. vue通过get方法下载java服务器excel模板

    vue方法 handleDownTemplateXls(fileName){ if(!fileName || typeof fileName != "string"){ fileN ...

  2. 前端学习 之 JavaScript DOM 与 BOM

    一. DOM介绍 1. 什么是DOM? DOM:文档对象模型.DOM 为文档提供了结构化表示,并定义了如何通过脚本来访问文档结构. 目的其实就是为了能让js操作html元素而制定的一个规范. DOM就 ...

  3. Java日期时间API系列9-----Jdk8中java.time包中的新的日期时间API类的Period和Duration的区别

    1.Period final修饰,线程安全,ISO-8601日历系统中基于日期的时间量,例如2年3个月4天. 主要属性:年数,月数,天数. /** * The number of years. */ ...

  4. win10 免安装版本的MySQL的下载安装和配置

    一.概述 网上找了好多,发现好多不是linux系统的就是与现在新版本有出入,自己做小项目亲手实践了一下,供大家借鉴. MySQL版本:mysql-5.7.17 下载方法: 1.MySQL官方网址htt ...

  5. Ionic3记录之核心代码分析

    app.module.ts app的根模块,一些插件的引用需要在这里声明,告诉APP如何组装应用: app.componet.ts app的根组件,主要用来APP启动时和启动后的操作;

  6. FiBiNET-学习

    Our main contributions are listed as follows: • Inspired by the success of SENET in the computer vis ...

  7. 捣鼓FileZilla

    今天突然对ftp服务器感兴趣,于是随意打了一个ftp词条,发现了FZ官网,好奇点进去下载了之后,捣鼓了一会.于是,也写一个小教程记录一下吧,害怕自己以后忘记怎么弄的了. 首先需要用到两个,一个是FZ ...

  8. linux kill命令以及 信号

    kill命令介绍 命令作用 终止一个进程 语法: kill [-s signal|-p] [-q sigval] [-a] [--] pid... kill -l [signal] 选项 -l 信号, ...

  9. SpringCloud+Eureka+Feign+Ribbon的简化搭建流程,加入熔断,网关和Redis缓存[2]

    目录 前提:本篇是基于 SpringCloud+Eureka+Feign+Ribbon的简化搭建流程和CRUD练习[1] 的修改与拓展 1.修改consumer的CenterFeign.java,把返 ...

  10. 把PHP大牛记下来,方便以后关注

    本帖最后由 fish_study 于 2014-12-31 00:18 编辑 五四陈科学院博主54chen(陈臻),哥学社创始人,前人人网分布式存储nuclear研发人员,现关注erlang.hado ...