CodeForces 869C The Intriguing Obsession【排列组合】
来源:互联网 发布:中国网络好声音 编辑:程序博客网 时间:2024/06/11 02:48
题目链接:http://codeforces.com/contest/869/problem/C
题意:有3种点,数量分别为a,b,c,让你对这3种点相互连线,使得相同种类点之间的最短距离至少为3,或者不连通,问你总共有多少种方法
解析:由于最短距离至少为3,那么内部肯定是不能相互连线的,那么需要考虑的就是和其他种类连,那这样的情况下,无论你怎么连,只会有要么不连通,要么最短距离只能为3,所以你求一下全部的方案数即可,对于a到b,b到c,a到c,因为是分步骤,所以是方法数相乘,所以分开来讨论a到b即可,其他事类似的,a到b,至多连min(a,b)条线,连k条线的方法数为,C(a,k)*A(b,k),只需要跑个循环,方法数就能算出来了
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1e4+100;const int mod = 998244353;ll h[maxn];ll qpow(ll x,ll n){ ll res = 1; while(n) { if(n&1) res = res*x%mod; x = x*x%mod; n >>= 1; } return res;}ll cal(int a,int b){ ll ans = 0; for(int i=0;i<=min(a,b);i++) { ll t1 = h[i]*h[a-i]%mod; t1 = h[a]*qpow(t1,mod-2)%mod; ll t2 = h[b]*qpow(h[b-i],mod-2)%mod; ans = (ans+t1*t2%mod)%mod; } return ans;}int main(void){ h[0] = 1; for(int i=1;i<5005;i++) h[i] = h[i-1]*i%mod; int a,b,c; scanf("%d %d %d",&a,&b,&c); //a to b ll ans = cal(a,b); // a to c ans = ans*cal(a,c)%mod; // b to c ans = ans*cal(b,c)%mod; printf("%I64d\n",ans); return 0;}
阅读全文
0 0
- CodeForces 869C The Intriguing Obsession【排列组合】
- codeforces 869C The Intriguing Obsession 组合数学,逆元
- Codeforces 869 C. The Intriguing Obsession (组合数学)
- codeforces 869C. The Intriguing Obsession(组合数学)
- codeforces 869C The Intriguing Obsession 组合数学
- [杂题 DP] Codeforces 869C. The Intriguing Obsession
- Codeforces 869C The Intriguing Obsession【组合数】
- 【Codeforces 869 C The Intriguing Obsession】& 组合数学 & 思维
- codeforces—— 869C —— The Intriguing Obsession
- Codeforces-869C The Intriguing Obsession(DP/组合数)
- Codeforces Round #439 (Div. 2) 869 C. The Intriguing Obsession
- Codeforces Round439 C.The Intriguing Obsession
- Codefrces 869C. The Intriguing Obsession
- Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
- Codeforces Round #439 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)
- IOCP服务器/客户端实现
- 通达OA麦枫自定义OA菜单的方法
- 1 概述
- ireport模版设计
- php api返回数据正常code却是500
- CodeForces 869C The Intriguing Obsession【排列组合】
- Qt常用类QChar
- 《快彩网》彩票php源码 使用thinkphp框架开发 实测截图
- linux配置文件的一些调优
- PAT乙级题1014.福尔摩斯的约会
- 在Java中关于静态变量和全局变量什么时候初始化的问题
- mysql创建各类索引的方法
- ubuntu 16.04 64 编译 openjdk7
- Windows快捷键大全