HDU 6064 RXD and numbers
传送门
有向图生成树计数 (度数 ->入度->外向树)
BEST定理 (不定起点的欧拉回路个数=某点为根的外向树个数(存在欧拉回路->每个点为根的外向树个数相等)*(每个点的度数(存在欧拉回路->每个点入度=出度)-1)的阶层)
一个题解的传送门
![](/assets/blank.gif)
![](/assets/blank.gif)
1 //Achen 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 #include<cstdlib> 6 #include<vector> 7 #include<cstdio> 8 #include<queue> 9 #include<cmath> 10 #include<set> 11 #include<map> 12 #define Formylove return 0 13 #define For(i,a,b) for(int i=(a);i<=(b);i++) 14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--) 15 const int N=505,p=998244353; 16 typedef long long LL; 17 typedef double db; 18 using namespace std; 19 LL n,d[N][N],fac[8000007],in[N],out[N]; 20 21 template<typename T>void read(T &x) { 22 char ch=getchar(); x=0; T f=1; 23 while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); 24 if(ch=='-') f=-1,ch=getchar(); 25 for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f; 26 } 27 28 LL a[N][N]; 29 LL gauss(int n) { 30 For(i,1,n) For(j,1,n) (a[i][j]+=p)%=p; 31 LL rs=1,f=1; 32 For(i,1,n) { 33 For(j,i+1,n) { 34 LL A=a[i][i],B=a[j][i]; 35 while(B) { 36 LL t=A/B; A%=B; swap(A,B); 37 For(k,i,n) a[i][k]=(a[i][k]-t*a[j][k]%p+p)%p; 38 For(k,i,n) swap(a[i][k],a[j][k]); f=-f; 39 } 40 } 41 rs=rs*a[i][i]%p; 42 } 43 if(f==-1) rs=(p-rs)%p; 44 return rs; 45 } 46 47 LL ksm(LL a,LL b) { 48 LL rs=1,bs=a%p; 49 while(b) { 50 if(b&1) rs=rs*bs%p; 51 bs=bs*bs%p; 52 b>>=1; 53 } 54 return rs; 55 } 56 57 int main() { 58 #ifdef ANS 59 freopen(".in","r",stdin); 60 freopen(".out","w",stdout); 61 #endif 62 fac[0]=1; int cas=0; 63 For(i,1,1000000) fac[i]=fac[i-1]*i%p; 64 while(~scanf("%lld",&n)) { 65 cas++; 66 For(i,1,n) in[i]=out[i]=0; 67 For(i,1,n) For(j,1,n) a[i][j]=0; 68 For(i,1,n) For(j,1,n) { 69 read(d[i][j]); 70 a[i][j]-=d[i][j]; 71 a[j][j]+=d[i][j]; 72 (out[i]+=d[i][j])%=p; 73 (in[j]+=d[i][j])%=p; 74 } 75 int fl=0; 76 For(i,1,n) if(in[i]!=out[i]) { 77 fl=1; break; 78 } 79 if(fl) { 80 printf("Case #%d: 0\n", cas); 81 continue; 82 } 83 For(i,2,n) For(j,2,n) a[i-1][j-1]=a[i][j]; 84 LL ans=gauss(n-1); 85 For(i,2,n) 86 ans=ans*fac[in[i]-1]%p; 87 ans=ans*fac[in[1]]%p; 88 For(i,1,n) For(j,1,n) if(d[i][j]) 89 ans=ans*ksm(fac[d[i][j]],p-2)%p; 90 printf("Case #%d: %lld\n",cas,ans); 91 } 92 Formylove; 93 } 94 /* 95 5 96 0 1 0 0 0 97 0 0 1 0 4 98 0 0 0 5 0 99 1 5 0 0 0 100 0 0 0 1 0 101 */
View Code
转载于:https://www.cnblogs.com/Achenchen/p/9499687.html
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 ...
- 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]-6060 RXD and dividing
URL : http://acm.hdu.edu.cn/showproblem.php?pid=6060 RXD has a tree T, with the size of n. Each edge ...
- HDU 6061 RXD and functions(NTT)
RXD and functions 首先是有一个结论,对多项式做任意多次 transformation ,其结果跟做一次 transformation Tr(f,∑i=1mai)Tr(f, \sum\ ...
- (HDU)1058 --Humble Numbers( 丑数)
题目链接:http://vjudge.net/problem/HDU-1058 这题有点难度,自己写了半天依旧TLE,参考了其他人的博客. http://blog.csdn.net/pythonfx/ ...
- 基尔霍夫定理 Kirchhoff's Matrix-Tree Theorem
推荐博客: 基尔霍夫定理 直观应用: 给定一个无向图/有向图G,求它生成树的个数t(G) 可以运用高斯消元求矩阵行列式(高斯消元法有待学习) 例题: HDU 6064 RXD and numbers ...
- 杭电OJ分类题目(2)
原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...
- HDU 5676 ztr loves lucky numbers
-亚信科技,巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州) (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队? ztr loves lucky numbers Time Li ...
- HDU 1492 The number of divisors(约数) about Humble Numbers(数论,简单约数)
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
最新文章
- LeetCode:383. Ransom Note
- .bash_profile 写入时间格式YYYY-MM-DD HH24:MI:SS 时报错 not a valid identifier
- 【NLP】NLP重铸篇之Fasttext
- 元组-元组变量的常用操作
- 优启通怎么重装系统win10_重装系统失败?小编教你安全给神舟战神GX9 Pro重装win10系统方法...
- Nodejs学习笔记02【module】
- php提取ip源码,PHP(源码) 如何获取客户端的IP地址
- 华为olt ma5680t常用命令详解
- MIPS处理器 CPU数据通路
- opencv 识别微信登录验证滑动块位置
- 指纹识别系统电路设计图集锦 —电路图天天读(200)
- MDCC 2016参会总结
- 元引擎视频制作工具 一键生成原创视频软件
- python 条件语句实例_详解python 条件语句和while循环的实例代码
- 0.进校的第一张Excel表:“住宿分布表” ——《Excel“智能化”之路》 系列文章
- c语言规定 标识符由,C语言规定标识符只能由字母、数字和小数点三种字符组成。()...
- 网站首页html静态化,网站首页怎么静态化
- hadoop学习-1
- 牛客网刷题——二叉树
- 吾爱第三课-修改版权和资源
热门文章
- Android 基础 —— 活动的生存周期
- [Mojava 10.14.4] Clover隐藏多余分区, 原来可以这么简单
- 显示当前行号、文件名和函数名(二)
- js reduce数组循环相加x+y
- register_sysctl_table实现内核数据交互
- [html] 如何关闭HTML页面在IOS下的键盘首字母自动大写?
- [html] 写一个搜索框,聚焦时搜索框向左拉长并有动画效果
- [html] 如何实现标题栏闪烁、滚动的效果
- [jQuery] jQuery的队列是如何实现的?队列可以用在哪些地方?
- 12人类为什么有战争