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 ...
随机推荐
- DEV插件下的控件Grid和Gridlookupedit控件的结合使用
创建GridlookupEtid控件 设置其对应属性: 设置属性 this.gridLookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEdit ...
- (PASS)java中nextInt()函数
一:获取随机数的函数: package test; import java.util.Random; /** * * @ClassName: NextIntDemo * @Description: n ...
- ElementUI的Loading组件 —— 想实现在请求后台数据之前开启Loading组件,请求成功或失败之后,关闭Loading组件
我在实际项目开发中,遇到了这个需求,记录一下~~~~~~ 在ElementUI官网上有几种实现Loading的方法,但官网上是在一个方法里写了开启与关闭组件,所以可以根据官网的实现方法进行一个封装,便 ...
- msql数据库基础
一.数据库操作 1.显示数据库 SHOW DATABASES; SHOW CREATE DATABASE 数据库名称; #数据库的创建信息 2.创建数据库 #utf8 CREATE DATABASE ...
- 强大的httpClientUtils
<!-- https://mvnrepository.com/artifact/com.arronlong/httpclientutil --> <dependency> &l ...
- 单源最短路径问题2 (Dijkstra算法)
用邻接矩阵 /* 单源最短路径问题2 (Dijkstra算法) 样例: 5 7 0 1 3 0 3 7 1 2 4 1 3 2 2 3 5 2 4 6 3 4 4 输出: [0, 3, 7, 5, 9 ...
- http经典解析
HTTP访问流程想象用浏览器打开imooc.com网站,HTTP走过的环节: 1.首先,是对imooc.com域名解析, (1.1)浏览器搜索浏览器自身的DNS缓存. (1.2)如果浏览器没有找到自身 ...
- NX二次开发-UFUN获取工程图视图边界线颜色UF_DRAW_ask_border_color
#include <uf.h> #include <uf_draw.h> #include <uf_ui.h> UF_initialize(); ; UF_DRAW ...
- (转)在Struts 2.0中国际化(i18n)您的应用程序 + 本人拓展备注
转:http://www.blogjava.net/max/archive/2006/11/01/78536.html 国际化是商业系统中不可或缺的一部分,所以无论您学习的是什么Web框架,它都是必须 ...
- hibernate 一对多查询 对多的一方进行分页
//查询用户留言@Overridepublic List<LeaveWords> getLeaveWords(String userName) {Session session = nul ...