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 (看题解) 组合数学的更多相关文章

  1. Codeforces 1109D. Sasha and Interesting Fact from Graph Theory

    Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m ...

  2. Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 排列组合,Prufer编码

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离 ...

  3. CF1109D Sasha and Interesting Fact from Graph Theory

    CF1109D Sasha and Interesting Fact from Graph Theory 这个 \(D\) 题比赛切掉的人基本上是 \(C\) 题的 \(5,6\) 倍...果然数学计 ...

  4. Sasha and Interesting Fact from Graph Theory CodeForces - 1109D (图论,计数,Caylay定理)

    大意: 求a->b最短路长度为m的n节点树的个数, 边权全部不超过m 枚举$a$与$b$之间的边数, 再由拓展$Caylay$定理分配其余结点 拓展$Caylay$定理 $n$个有标号节点生成k ...

  5. Codeforces1113F. Sasha and Interesting Fact from Graph Theory(组合数学 计数 广义Cayley定理)

    题目链接:传送门 思路: 计数.树的结构和边权的计数可以分开讨论. ①假设从a到b的路径上有e条边,那么路径上就有e-1个点.构造这条路径上的点有$A_{n-2}^{e-1}$种方案: ②这条路径的权 ...

  6. CF1109DSasha and Interesting Fact from Graph Theory(数数)

    题面 传送门 前置芝士 Prufer codes与Generalized Cayley's Formula 题解 不行了脑子已经咕咕了连这么简单的数数题都不会了-- 首先这两个特殊点到底是啥并没有影响 ...

  7. Codeforces 316E3 线段树 + 斐波那切数列 (看题解)

    最关键的一点就是 f[ 0 ] * a[ 0 ] + f[ 1 ] * a[ 1 ] + ... + f[ n - 1] * a[ n  - 1] f[ 1 ] * a[ 0 ] + f[ 2 ] * ...

  8. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  9. Codeforces 703D Mishka and Interesting sum 离线+树状数组

    链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...

随机推荐

  1. [BZOJ 2242] [SDOI 2011] 计算器

    Description 你被要求设计一个计算器完成以下三项任务: 给定 \(y,z,p\),计算 \(y^z \bmod p\) 的值: 给定 \(y,z,p\),计算满足 \(xy≡ z \pmod ...

  2. Transaction check error: file /etc/rpm/macros.ghc-srpm from install of redhat-rpm-config-9.1.0-80.el7.centos.noarch conflicts with file from package epel-release-6-8.noarch Error Summary ----------

    ./certbot-auto certonly 报错: Transaction check error:   file /etc/rpm/macros.ghc-srpm from install of ...

  3. SDOI2017 Round2 详细题解

    这套题实在是太神仙了..做了我好久...好多题都是去搜题解才会的 TAT. 剩的那道题先咕着,如果省选没有退役就来填吧. 「SDOI2017」龙与地下城 题意 丢 \(Y\) 次骰子,骰子有 \(X\ ...

  4. Linux下安装部署Samba共享盘的操作手册

    简述 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的 ...

  5. Numpy系列(十)- 掩码数组

    简介 有时候数据集中存在缺失.异常或者无效的数值,我们可以标记该元素为被屏蔽(无效)状态. import numpy as np import numpy.ma as ma x = np.array( ...

  6. 安装mysql和xampp遇到问题

    1.mysql的期望地址和配置的地址不一致: 解决方法:修改注册表 在附件命令提示符输入regedit 找[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Se ...

  7. [再寄小读者之数学篇](2014-09-22 distributions and square integrable functions)

    Suppose that $f\in L^2$, $g\in \scrD'$, if $$\bex f=g,\mbox{ in }\scrD', \eex$$ then $f=g\in L^2$. I ...

  8. 关于使用 JSON.parse()报 VM141:1 Uncaught SyntaxError 的解决方案

    今天在使用ajax的后期,老师问我们怎么json解析对象,然后上百度搜了一下:大概有三个方式 var str = '{"name":"小明","age ...

  9. ST表学习笔记

    ST表是一种利用DP思想求解最值的倍增算法 ST表常用于解决RMQ问题,即求解区间最值问题 接下来以求最大值为例分步讲解一下ST表的建立过程: 1.定义 f[i][j]表示[i,i+2j-1]这个长度 ...

  10. 推荐安全且匿名的邮箱 ProtonMail -- PGP算法

    ==以前一直以为平时所用的邮箱是绝对安全的,没有深思它的安全性. 然而你要“犯罪”不留任何痕迹的话,呵呵. 国内应该没有类似 ProtonMail 的邮箱,-->去了解一下 ========== ...