Sasha and Interesting Fact from Graph Theory

n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m}

然后就没啥难度了。。。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define LD long double
  4. #define ull unsigned long long
  5. #define fi first
  6. #define se second
  7. #define mk make_pair
  8. #define PLL pair<LL, LL>
  9. #define PLI pair<LL, int>
  10. #define PII pair<int, int>
  11. #define SZ(x) ((int)x.size())
  12. #define ALL(x) (x).begin(), (x).end()
  13. #define fio ios::sync_with_stdio(false); cin.tie(0);
  14.  
  15. using namespace std;
  16.  
  17. const int N = 1e6 + ;
  18. const int inf = 0x3f3f3f3f;
  19. const LL INF = 0x3f3f3f3f3f3f3f3f;
  20. const int mod = 1e9 + ;
  21. const double eps = 1e-;
  22. const double PI = acos(-);
  23.  
  24. template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
  25. template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
  26. template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
  27. template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}
  28.  
  29. int power(int a, int b) {
  30. int ans = ;
  31. while(b) {
  32. if(b & ) ans = 1LL * ans * a % mod;
  33. a = 1LL * a * a % mod; b >>= ;
  34. }
  35. return ans;
  36. }
  37.  
  38. int F[N], Finv[N], inv[N];
  39. int C(int n, int m) {
  40. if(n < || n < m) return ;
  41. return 1LL * F[n] * Finv[m] % mod * Finv[n - m] % mod;
  42. }
  43.  
  44. int n, m, a, b;
  45.  
  46. int main() {
  47. inv[] = F[] = Finv[] = ;
  48. for(int i = ; i < N; i++) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
  49. for(int i = ; i < N; i++) F[i] = 1LL * F[i - ] * i % mod;
  50. for(int i = ; i < N; i++) Finv[i] = 1LL * Finv[i - ] * inv[i] % mod;
  51. scanf("%d%d%d%d", &n, &m, &a, &b);
  52. int ans = ;
  53. for(int i = ; i <= n; i++) {
  54. 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);
  55. else add(ans, 1LL * F[i - ] * C(m - , i - ) % mod);
  56. }
  57. printf("%d\n", ans);
  58. return ;
  59. }
  60.  
  61. /*
  62. */

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. vue2.0实现过滤

    vue1.0和vue2.0差别还是挺多的,之前的vue1.0还有过滤器功能,到了2.0过滤器只能通过自己编写.以下是写的一个小demo: HTML <div id="app" ...

  2. RBAC权限管理系统

    RBAC--基于角色的权限管理系统 优势: 1. 简化了用户和权限的关系 2. 易扩展,易于维护 3. RBAC不用给用户单个分配权限,只用指向对应的角色就会有对应的权限,而且分配权限和收回权限都很方 ...

  3. 20175221 《Java程序设计》第5周学习总结

    20175221   <Java程序设计>第5周学习总结 教材学习内容总结 接口的定义 接口声明:interface 接口名 接口体中只可以有常量,而没有变量 接口体中只有抽象方法(可省略 ...

  4. 利用 /proc/sys/kernel/core_pattern隐藏系统后门

    ref:https://xz.aliyun.com/t/1098/ 这里所说的core_pattern 指的是:/proc/sys/kernel/core_pattern. 我们知道在Linux系统中 ...

  5. windows下使用curl命令 && 常用curl命令

    什么是curl命令? curl是利用URL语法在命令行方式下工作的开源文件传输工具.它被广泛应用在Unix.多种Linux发行版中,并且有DOS和Win32.Win64下的移植版本. 如何在windo ...

  6. DirectX11 With Windows SDK--11 混合状态与光栅化状态

    前言 虽然这一部分的内容主要偏向于混合(Blending),但这里还需提及一下,关于渲染管线可以绑定的状态主要有如下四种: 光栅化状态(光栅化阶段) 采样器状态(像素着色阶段) 混合状态(输出合并阶段 ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(期望+暴力)

    https://nanti.jisuanke.com/t/31455 题意 给一个3*3的方格填入 1-9 九个数 有些数是已知的,有些数是对方已知但我未知的,有些数是大家都未知的 我要计算取得最大的 ...

  8. CSS 书写规范

    class 类名的命名应该以功能为依据: 例如: .btn-danger;  .btn-warning CSS组件 一个组件==一个独立的功能模块 针对一个组件,通过功能描述样式   组件命名,功能描 ...

  9. django - 总结 - 用户认证组件

    用户认证组件 from django.contrib import auth 从auth_user表中获取对象,没有返回None,其中密码为密文,使用了加密算法 user = auth.authent ...

  10. [物理学与PDEs]第5章习题3 第二 Piola 应力张量的对称性

    试证明: 在物质描述下, 动量矩守恒定律等价于第二 Piola 应力张量的对称性. 证明: 由 $$\beex \bea \int_{G_t}\rho\sex{{\bf y}\times\cfrac{ ...