HDU 6064 RXD and numbers
有向图生成树计数 (度数 ->入度->外向树)
BEST定理 (不定起点的欧拉回路个数=某点为根的外向树个数(存在欧拉回路->每个点为根的外向树个数相等)*(每个点的度数(存在欧拉回路->每个点入度=出度)-1)的阶层)
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define Formylove return 0
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=,p=;
typedef long long LL;
typedef double db;
using namespace std;
LL n,d[N][N],fac[],in[N],out[N]; template<typename T>void read(T &x) {
char ch=getchar(); x=; T f=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} LL a[N][N];
LL gauss(int n) {
For(i,,n) For(j,,n) (a[i][j]+=p)%=p;
LL rs=,f=;
For(i,,n) {
For(j,i+,n) {
LL A=a[i][i],B=a[j][i];
while(B) {
LL t=A/B; A%=B; swap(A,B);
For(k,i,n) a[i][k]=(a[i][k]-t*a[j][k]%p+p)%p;
For(k,i,n) swap(a[i][k],a[j][k]); f=-f;
}
}
rs=rs*a[i][i]%p;
}
if(f==-) rs=(p-rs)%p;
return rs;
} LL ksm(LL a,LL b) {
LL rs=,bs=a%p;
while(b) {
if(b&) rs=rs*bs%p;
bs=bs*bs%p;
b>>=;
}
return rs;
} int main() {
#ifdef ANS
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
fac[]=; int cas=;
For(i,,) fac[i]=fac[i-]*i%p;
while(~scanf("%lld",&n)) {
cas++;
For(i,,n) in[i]=out[i]=;
For(i,,n) For(j,,n) a[i][j]=;
For(i,,n) For(j,,n) {
read(d[i][j]);
a[i][j]-=d[i][j];
a[j][j]+=d[i][j];
(out[i]+=d[i][j])%=p;
(in[j]+=d[i][j])%=p;
}
int fl=;
For(i,,n) if(in[i]!=out[i]) {
fl=; break;
}
if(fl) {
printf("Case #%d: 0\n", cas);
continue;
}
For(i,,n) For(j,,n) a[i-][j-]=a[i][j];
LL ans=gauss(n-);
For(i,,n)
ans=ans*fac[in[i]-]%p;
ans=ans*fac[in[]]%p;
For(i,,n) For(j,,n) if(d[i][j])
ans=ans*ksm(fac[d[i][j]],p-)%p;
printf("Case #%d: %lld\n",cas,ans);
}
Formylove;
}
/*
5
0 1 0 0 0
0 0 1 0 4
0 0 0 5 0
1 5 0 0 0
0 0 0 1 0
*/
HDU 6064 RXD and numbers的更多相关文章
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- HDU 6061 - RXD and functions | 2017 Multi-University Training Contest 3
每次NTT都忘记初始化,真的是写一个小时,Debug两个小时- - /* HDU 6061 - RXD and functions [ NTT ] | 2017 Multi-University Tr ...
- HDU 6060 - RXD and dividing | 2017 Multi-University Training Contest 3
/* HDU 6060 - RXD and dividing [ 分析,图论 ] | 2017 Multi-University Training Contest 3 题意: 给一个 n 个节点的树, ...
- HDU 6063 - RXD and math | 2017 Multi-University Training Contest 3
比赛时候面向过题队伍数目 打表- - 看了题解发现确实是这么回事,分析能力太差.. /* HDU 6063 - RXD and math [ 数学,规律 ] | 2017 Multi-Universi ...
- hdu 6063 RXD and math(快速幂)
RXD and math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- hdu 5272 Dylans loves numbers
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...
- hdu 5272 Dylans loves numbers 水题
Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...
- 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)
题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...
- hdu 1058 dp.Humble Numbers
Humble Numbers Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- 10_PAE_非PAE
前置知识: 在 windows 中 保护模式 有两种模式: 段保护 和 页保护 段保护 主要体现在 段选择子上:但是数据段.代码段.栈段等采用的都是4GB平坦模式,段的特征并没有那样展现.所以具体的保 ...
- vue实现京东动态楼层效果
页面效果如下 <template> <div> <h1>首页</h1> <section class="floor-nav" ...
- python+selenium遍历某一个标签中的内容
一.python+selenium遍历某一个标签中的内容 举个例子:我要获取列表标签<li></li>的内容 根据python+selenium定位到列表整体,使用for循环获 ...
- CSS3(@media)判断手机横竖屏
@media all and (orientation : landscape) { h2{color:red;}/*横屏时字体红色*/ } @media all and (orientation : ...
- leetcood学习笔记-118-杨辉三角
题目描述: 第一次提交: class Solution: def generate(self, numRows: int): l = [] for i in range(numRows): n = [ ...
- 揭秘!2周实现上云上市,阿里云SaaS上云工具包如何打造新云梯?
提到“上云”,很多人会理解成上IaaS,比如买一些计算.存储和网络云产品,把自己的应用系统部署上去.这的确是通常意义的上云.但对SaaS而言,需要从产品.商业.服务,三个维度考虑SaaS伙伴和客户的痛 ...
- delphi 不规则窗体与桌面宠物
二.支持区域操作的编程接口在Windows的API函数中有一组用于区域操作的函数,可以用来生成区域.合并区域.获取区域数据.根据数据生成区域.把区域和窗体联系等,其中常用的几个函数有:生成矩形区域的C ...
- Delphi中的Sender:TObject对象解析转载
https://blog.csdn.net/jl_tiny/article/details/24376661 Delphi中的Sender:TObject对象解析 procedure TForm1.B ...
- 2019 IEEEXtreme 13.0 题解记录
比赛时间 2019.10.19 8:00 - 2019.10.20 8:00 比赛网站 https://csacademy.com/ieeextreme13 // 连续24小时做题真的是极限体验 // ...
- 20140319 const sizeof define 编译时分配内存
1.面试宝典预处理,const,sizeof Define作用定义函数: //用一个宏定义FIND求一个结构体struc里某个变量相对于struc的偏移量,如FIND(student,a)//等于0 ...