Codeforces Round #439 C. The Intriguing Obsession (组合数)
来源:互联网 发布:虚拟固话软件 编辑:程序博客网 时间:2024/05/22 01:36
Problem
有三个岛群,分别有 a, b, c 个岛屿。要求在这三个岛群建桥(可以不建),问有多少种不同的建桥方案(有任意一座桥的任意一个端点不同即视为不同方案)。
要求:每座桥的长记为 1,属于同一岛群的两个岛间最短距离至少为 3 ,或者两岛不存在路径。
Idea
由于同岛群的任意两岛最短距离至少为 3 或不能有路径。则可知,非法路径的连接方案为:
- 同岛群两岛直接连接。
- 同岛群两岛均与另一岛群的某岛连接。
故反向条件为:任意两岛群之间取任意 k (
Code
#include<bits/stdc++.h>using namespace std;const int mod = 998244353;int a, b, c;long long C[5010][5010], fac[5010];void init(){ C[0][0] = 1; fac[0] = 1; for(int i=1;i<=5000;i++) { (fac[i] = fac[i-1] * i) %= mod; 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; } }long long solve(long long x, long long y){ long long mn = min(x, y); long long ret = 1; long long tmp; for(int i=1;i<=mn;i++) { tmp = C[x][i] * C[y][i] % mod * fac[i] % mod; ret = (ret + tmp) % mod; } return ret;}int main(){ init(); scanf("%d %d %d", &a, &b, &c); long long ans = solve(a, b) * solve(b, c) % mod * solve(a, c) % mod; printf("%lld\n", ans);}
阅读全文
0 0
- Codeforces Round #439 C. The Intriguing Obsession (组合数)
- Codeforces Round #439C 组合数-The Intriguing Obsession
- Codeforces Round #439 C.The Intriguing Obsession(组合数学)
- Codeforces Round #439 (Div. 2)C. The Intriguing Obsession (组合数详解)
- Codeforces-869C The Intriguing Obsession(DP/组合数)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession(组合数)
- Codeforces Round #439 (Div. 2) C.The Intriguing Obsession(组合数、记忆化搜索)
- Codeforces 869C The Intriguing Obsession【组合数】
- Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
- Codeforces Round #439 (Div. 2) C 869C The Intriguing Obsession(思维+简单组合)
- Codeforces Round #439 (Div. 2) C The Intriguing Obsession (组合数学)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- Codeforces Round #439 C The Intriguing Obsession(dp)
- Codeforces Round #439 C.The Intriguing Obsession(DP + 思维)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession dp
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession
- python里使用正则表达式的重复模式
- 用node从零开始去写一个简单的爬虫
- java写入文件的几种方法
- HTML CSS 定位 position
- 批量图片灰度化小程序
- Codeforces Round #439 C. The Intriguing Obsession (组合数)
- 基于Angular+express的定时爬虫信息综合application
- [DevExpress使用随笔]之RibbonReportDesigner控件
- HDFS SHELL命令大全
- 【SqlMap】SQL注入之初体验
- React中调用百度地图
- Spring面向切面编程——Spring实现AOP方式——通过Spring API实现
- (转)Windows平台使用Gitblit搭建Git服务器图文教程
- 适配器模式 Adapter