zoukankan      html  css  js  c++  java
  • bzoj4766 文艺计算姬

    Description

    "奋战三星期,造台计算机"。小W响应号召,花了三星期造了台文艺计算姬。文艺计算姬比普通计算机有更多的艺术细胞。普通计算机能计算一个带标号完全图的生成树个数,而文艺计算姬能计算一个带标号完全二分图的生成树个数。更具体地,给定一个一边点数为n,另一边点数为m,共有n*m条边的带标号完全二分图K_{n,m},计算姬能快速算出其生成树个数。小W不知道计算姬算的对不对,你能帮助他吗?

    Input

    仅一行三个整数n,m,p,表示给出的完全二分图K_{n,m}
    1 <= n,m,p <= 10^18

    Output

    仅一行一个整数,表示完全二分图K_{n,m}的生成树个数,答案需要模p。

    Sample Input

    2 3 7

    Sample Output

    5

    正解:矩阵树定理+快速幂+黑科技乘法。
    很水的一道题。。用矩阵树定理打表以后就发现$Ans=m^{n-1}*n^{m-1}$,然后可以先快速幂然后黑科技乘法解决。

     1 //It is made by wfj_2048~
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <complex>
     5 #include <cstring>
     6 #include <cstdlib>
     7 #include <cstdio>
     8 #include <vector>
     9 #include <cmath>
    10 #include <queue>
    11 #include <stack>
    12 #include <map>
    13 #include <set>
    14 #define inf (1<<30)
    15 #define eps (1e-9)
    16 #define il inline
    17 #define RG register
    18 #define ll long long
    19 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
    20 
    21 using namespace std;
    22 
    23 ll n,m,p;
    24 
    25 il ll mul(RG ll a,RG ll b){
    26     return (ll)(a*b-(ll)((long double)a/p*b+0.5)*p+p)%p;
    27 }
    28 
    29 il ll qpow(RG ll a,RG ll b){
    30     RG ll ans=1;
    31     while (b){
    32     if (b&1) ans=mul(ans,a);
    33     a=mul(a,a),b>>=1;
    34     }
    35     return ans;
    36 }
    37 
    38 int main(){
    39     File("ji");
    40     cin>>n>>m>>p;
    41     RG ll a=qpow(n%p,m-1),b=qpow(m%p,n-1);
    42     printf("%lld",mul(a,b));
    43     return 0;
    44 }
  • 相关阅读:
    【高软作业4】:Tomcat 观察者模式解析 之 Lifecycle
    Eclipse 导入 Tomcat 源码
    【高软作业3】:原型化系统 DevTools
    Java Obejct
    Java PriorityQueue
    【高软作业2】:Java IDE调研分析
    GitHub fork 合作开发 快速实现版
    用C#实现天气预报(调用WebService)
    hover和点击事件之间的冲突
    BurpSuite2021系列(三)新建扫描
  • 原文地址:https://www.cnblogs.com/wfj2048/p/6658148.html
Copyright © 2011-2022 走看看