Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学
Sasha and Interesting Fact from Graph Theory
n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m}
然后就没啥难度了。。。
#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0); using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} int power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = 1LL * ans * a % mod;
a = 1LL * a * a % mod; b >>= ;
}
return ans;
} int F[N], Finv[N], inv[N];
int C(int n, int m) {
if(n < || n < m) return ;
return 1LL * F[n] * Finv[m] % mod * Finv[n - m] % mod;
} int n, m, a, b; int main() {
inv[] = F[] = Finv[] = ;
for(int i = ; i < N; i++) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
for(int i = ; i < N; i++) F[i] = 1LL * F[i - ] * i % mod;
for(int i = ; i < N; i++) Finv[i] = 1LL * Finv[i - ] * inv[i] % mod;
scanf("%d%d%d%d", &n, &m, &a, &b);
int ans = ;
for(int i = ; i <= n; i++) {
if(i < n) add(ans, 1LL * C(n - , i - ) * F[i - ] % mod * C(m - , i - ) % mod * power(m, n - i) % mod * i % mod * power(n, n - i - ) % mod);
else add(ans, 1LL * F[i - ] * C(m - , i - ) % mod);
}
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学的更多相关文章
- Codeforces 1109D. Sasha and Interesting Fact from Graph Theory
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m ...
- Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 排列组合,Prufer编码
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离 ...
- CF1109D Sasha and Interesting Fact from Graph Theory
CF1109D Sasha and Interesting Fact from Graph Theory 这个 \(D\) 题比赛切掉的人基本上是 \(C\) 题的 \(5,6\) 倍...果然数学计 ...
- Sasha and Interesting Fact from Graph Theory CodeForces - 1109D (图论,计数,Caylay定理)
大意: 求a->b最短路长度为m的n节点树的个数, 边权全部不超过m 枚举$a$与$b$之间的边数, 再由拓展$Caylay$定理分配其余结点 拓展$Caylay$定理 $n$个有标号节点生成k ...
- Codeforces1113F. Sasha and Interesting Fact from Graph Theory(组合数学 计数 广义Cayley定理)
题目链接:传送门 思路: 计数.树的结构和边权的计数可以分开讨论. ①假设从a到b的路径上有e条边,那么路径上就有e-1个点.构造这条路径上的点有$A_{n-2}^{e-1}$种方案: ②这条路径的权 ...
- CF1109DSasha and Interesting Fact from Graph Theory(数数)
题面 传送门 前置芝士 Prufer codes与Generalized Cayley's Formula 题解 不行了脑子已经咕咕了连这么简单的数数题都不会了-- 首先这两个特殊点到底是啥并没有影响 ...
- Codeforces 316E3 线段树 + 斐波那切数列 (看题解)
最关键的一点就是 f[ 0 ] * a[ 0 ] + f[ 1 ] * a[ 1 ] + ... + f[ n - 1] * a[ n - 1] f[ 1 ] * a[ 0 ] + f[ 2 ] * ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces 703D Mishka and Interesting sum 离线+树状数组
链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...
随机推荐
- Django之ContentType组件
一.理想表结构设计 1.初始构建 1. 场景刚过去的双12,很多电商平台都会对他们的商品进行打折促销活动的,那么我们如果要实现这样的一个场景,改如何设计我们的表? 2. 初始表设计 注释很重要,看看吧 ...
- C#嵌入动态链接库到可执行文件
C#嵌入动态链接库到可执行文件 将需要被集成的程序集放在项目的lib文件夹中,引用路径从解决方案开始,以“.”连接. 如图(解决方案名称为莫非): 核心代码: AppDomain.CurrentDom ...
- FileZilla-02
WordPress的权限方案 通常,所有文件应由您的Web服务器上的用户(ftp)帐户拥有,并且应该可由该帐户写入.在共享主机上,文件永远不应归Web服务器进程本身所有(有时这是www,或apache ...
- Codeforces1102F Elongated Matrix 【状压DP】
题目分析: 这题瞎搞一个哈密尔顿路,对于起点不同的分开跑就可以过了. $O(n^3*2^n)$ #include<bits/stdc++.h> using namespace std; ; ...
- JPA的merge对联合唯一索引无效(代码库)
问题 JPA的merge()操作 是合并的意思,就是当保存的实体时,根据主键id划分,如果已存在,那么就是更新操作,如果不存在,就是新增操作 但是这个仅针对 主键id 划分,对联合唯一索引 无效,两次 ...
- 2.2 collection 模块
2.2.1 定义命名元祖 2.2.2 定义双端队列 2.2.3 定义有序的字典 2.2.4 定义有默认值的字典
- mysql shell 定时备份
#!/bin/sh if [ ! -d "/data/backup" ]; then mkdir -p /data/backup fi db_user=" ...
- 转载:ORA-12516 “TNS监听程序找不到符合协议堆栈要求的可用处理程序” 解决方案
ORA-12516 “TNS监听程序找不到符合协议堆栈要求的可用处理程序” 解决方案 简单描述一下场景,总共两台应用服务器,每台安装3个tomcat进行集群,并通过nginx做了负载均衡,今天在生 ...
- tty
tty一词源于Teletypes,或teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘和显示器取代,所以现在叫终端比较合适. 终端 ...
- EF CodeFirst系列(7)---FluentApi配置存储过程
FluentApi配置存储过程 1.EF自动生成存储过程 EF6的CodeFirst开发模式支持给实体的CUD操作配置存储过程,当我们执行SaveChanges()方法时EF不在生成INSERT,UP ...