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 ...
随机推荐
- UVA11021 Tribles 概率dp
题目传送门 题意:开始有$k$只兔子,每只都是活一天就死,每只死前都会有$pi$的概率生出$i$只兔子.求$m$天后兔子死光的概率. 思路: 设$f[i]$为一只兔子在第i天死完的概率,那么答案就是$ ...
- 笔记38 Spring Web Flow——订单流程(定义基本流程)
做一个在线的披萨订购应用 实际上,订购披萨的过程可以很好地定义在一个流程中.我们首先从 构建一个高层次的流程开始,它定义了订购披萨的整体过程.接下 来,我们会将这个流程拆分成子流程,这些子流程在较低的 ...
- (PASS)什么是原子性和原子性操作?
什么是原子性操作呢? 下面我举一个例子来说明一下: A想要从自己的帐户中转1000块钱到B的帐户里.那么从A开始转帐,到转帐结束的这一个过程,称之为一个事务.在这个事务里,要做如下操作: 1. 从A的 ...
- CAS -- ABA问题的解决方案
我们现在来说什么是ABA问题.假设内存中有一个值为A的变量,存储在地址V中. 此时有三个线程想使用CAS的方式更新这个变量的值,每个线程的执行时间有略微偏差.线程1和线程2已经获取当前值,线程3还未获 ...
- openwrt usb
fdisk -l #以列表的形式,列出当前挂载盘的情况 for 属性规定 label 与哪个表单元素绑定 <form> <label for="male"> ...
- [转]WPF的依赖属性是怎么节约内存的
WPF升级了CLR的属性系统,加入了依赖属性和附加属性.依赖属性的使用有很多好处,其中有两点是我认为最为亮眼的: 1)节省内存的开销; 2)属性值可以通过Binding依赖于其它对象上,这就使得我的数 ...
- Linux下可以运行bat文件么?
bat是批处理文件,在windows和linux上都可以使用. 不过在linux的命令行中不可以直接敲"xxx.bat",系统会去找所有的命令. 想要调用bat文件,需要写绝对路径 ...
- Java 获取当前路径的方法总结
Java 获取当前路径的方法总结 1.利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user. ...
- ubuntu 16.04 jdk-8u201-linux-x64.tar.gz 安装部署
都是在普通用户加sudo代替root 1.sudo tar -zxvf jdk-8u201-linux-x64.tar.gz2.sudo chown make:make jdk1.8.0/3.sudo ...
- 1、Go语言的介绍
一.概念 Go语言(Golang)是云计算时代的C语言,使用Go编译的程序可以媲美C/C++代码的速度,而且更加安全.支持并行进程. 二.Go语言的优势 1.部署简单.可以直接编译成机器码,不依赖其他 ...