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 ...
随机推荐
- JS点击2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 逻辑右移函数 srl()与算术右移函数 sra() (转)
比如一个有符号位的8位二进制数11001101,逻辑右移就不管符号位,如果移一位就变成01100110.算术右移要管符号位,右移一位变成10100110. 逻辑左移=算数左移,右边统一添0 逻辑右移, ...
- shell脚本实现批量端口扫描
#!/bin/bash # Telnet Batach readonly TMOUT= ip_prefix="192.168" ip_network_range="80- ...
- pycharm 2020 激活码 破解教程
以下是安装完pycharm后进行破解!! 1.修改hosts,在hosts文件最后添加2行“0.0.0.0 account.jetbrains.com”和“0.0.0.0 www.jetbrain ...
- leetcode-132-分割回文串②*
题目描述: 方法一:动态规划 class Solution: def minCut(self, s: str) -> int: min_s = list(range(len(s))) n = l ...
- php数组函数,遍历数组的几种方法
数组创建: 1.array(): 生成一个数组 $a=array("Dog","Cat","Horse"); print_r($a);数组值 ...
- bzoj1217: [HNOI2003]消防局的设立 [树形dp]
Description 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达,所以所有的基地形成了 ...
- 线性基算贡献——19牛客多校第一场H
/* 给定数组a[],求有多少集合的异或值为0,将这些集合的大小之和求出来 对于每个数来说,如果除去这个数后数组里做出的线性基和这个数线性相关,那么这个数贡献就是2^(n-1-线性基的大小) 反之这个 ...
- 高可用开源方案Heartbeat vs Keepalived
转:http://www.kuqin.com/shuoit/20140623/340745.html 最近因为项目需要,简单的试用了两款高可用开源方案:Keepalived和Heartbeat.两者都 ...
- hdu多校第九场 1005 (hdu6684) Rikka with Game 博弈
题意: 给一个小写字母组成的字符串,每回合轮到某人时,此人可以选择让某位+1(如果是z则变回a),或者直接结束游戏. 先手希望游戏结束时字符串字典序尽量小,后手希望游戏结束时字符串字典序尽量大,求游戏 ...