LGP4841题解
无向联通图计数板子
首先,这个太难了,先让我们来求一个简单的:
无向图计数。
一共 \(\frac {n \times (n+1)} 2\) 条可能存在的边,枚举一条边是否存在,就有 \(2^{\frac {n \times (n+1)} 2}\) 个无向图。
回到本题,我们先设 \(f_n\) 是我们要求的 \(n\) 个无向联通图的个数, \(g_n\) 是 \(2^{\frac {n \times (n+1)} 2}\),很明显有:
\]
组合数后面的是一个卷积的形式,而组合数本身就是一堆阶乘,这在提示我们使用 EGF,并且本题的模数也是一个 NTT 模数。
\]
然后我们设 \(F(x)\) 是 { \(f_n\) } 的 EGF,\(G(x)\) 是 { \(g_n\) } 的 EGF。
很容易发现:\(g_n=[x^n]G'(x)\),然后就有:
\]
\]
\]
然后我们就做完了。
贴代码:
#include<cstring>
#include<cstdio>
#define clr(f,len) memset(f,0,(len)<<2)
#define cpy(f,g,len) memcpy(f,g,(len)<<2)
const int G=3,invG=334845270,mod=1004535809,M=7e5+5;
int n,t[M],f[M],inv[M],tor[M];
inline void swap(int&a,int&b){
a^=b^=a^=b;
}
inline void GetRev(int len){
for(int i=0;i<len;++i)t[i]=t[i>>1]>>1|(i&1?len>>1:0);
}
inline void px(int*f,int*g,int len){
for(int i=0;i<len;++i)f[i]=1ll*f[i]*g[i]%mod;
}
inline void der(int*f,int n){
for(int i=1;i<n;++i)f[i-1]=1ll*f[i]*i%mod;
f[n-1]=0;
}
inline void itg(int*f,int n){
for(int i=n;i;--i)f[i]=1ll*f[i-1]*inv[i]%mod;
f[0]=0;
}
inline int pow(int a,int b=mod-2){
int ans=1;
for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;
return ans;
}
void NTT(int*f,bool flag,int n){
int i,k,p,w,w1,len;
for(i=0;i<n;++i)if(i<t[i])swap(f[i],f[t[i]]);
for(p=2;p<=n;p<<=1){
len=p>>1;w1=pow(flag?G:invG,(mod-1)/p);
for(k=0;k<n;k+=p){
w=1;
for(i=k;i<k+len;++i){
int t=1ll*f[i+len]*w%mod;
if((f[i+len]=f[i]-t)<0)f[i+len]+=mod;
if((f[i]=f[i]+t)>mod)f[i]-=mod;
w=1ll*w*w1%mod;
}
}
}
if(flag)return;
int invN=pow(n);
for(i=0;i<n;++i)f[i]=1ll*f[i]*invN%mod;
}
void invp(int*f,int m){
static int b1[M],b2[M],b3[M];
int i,n=1,len;b1[0]=pow(f[0]);
while(n<m)n<<=1;
for(len=2;len<=n;len<<=1){
for(i=0;i<(len>>1);++i)b3[i]=(b1[i]<<1)%mod;
cpy(b2,f,len);
GetRev(len<<1);
NTT(b1,1,len<<1);px(b1,b1,len<<1);
NTT(b2,1,len<<1);px(b1,b2,len<<1);
NTT(b1,0,len<<1);clr(b1+len,len);
for(i=0;i<len;++i)b1[i]=(b3[i]-b1[i]+mod)%mod;
}
cpy(f,b1,m);clr(b1,n<<1);clr(b2,n<<1);clr(b3,n<<1);
}
void lnp(int*f,int n){
static int sav[M];
cpy(sav,f,n);
der(f,n);invp(sav,n);
GetRev(n<<1);
NTT(f,1,n<<1);NTT(sav,1,n<<1);
px(f,sav,n<<1);NTT(f,0,n<<1);
itg(f,n-1);
clr(f+n,n);clr(sav,n);
}
signed main(){
int i,m=1,tmp1,tmp2;
inv[1]=tor[0]=tor[1]=1;
scanf("%d",&n);++n;
while(m<n)m<<=1;
GetRev(m);
for(i=2;i<=m;++i){
inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
tor[i]=1ll*tor[i-1]*i%mod;
}
for(i=0;i<m;++i)f[i]=1ll*pow(2,(1ll*i*(i-1)>>1)%(mod-1))*pow(tor[i])%mod;
lnp(f,m);
printf("%d",1ll*f[n-1]*tor[n-1]%mod);
}
LGP4841题解的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- Google hacker
转载请注明来源:https://www.cnblogs.com/hookjc/ Google Hacking其实并算不上什么新东西,在早几年我在一些国外站点上就看见过相关的介绍,但是由于当时并没有重视 ...
- Java中线程的状态及其转化
线程状态转化图: 说明: 线程总共包括以下5种状态. 1.新状态New:该状态也叫新建状态,当线程对象被创建后,线程就进入了新建状态.例如:Thread thread = new Thread();. ...
- 【ASP.NET Core】设置 Web API 响应数据的格式——FormatFilter特性篇
在上一篇烂文中老周已向各位介绍过 Produces 特性的使用,本文老周将介绍另一个特性类:FormatFilterAttribute. 这个特性算得上是筛选器的马甲,除了从 Attribute 类派 ...
- nodejs串行无关联
var async = require('async'); //串行无关联async.series({ one:function(cb) { setTimeout(function(){ consol ...
- HTTP流量神器Goreplay核心源码详解
摘要:Goreplay 前称是 Gor,一个简单的 TCP/HTTP 流量录制及重放的工具,主要用 Go 语言编写. 本文分享自华为云社区<流量回放工具之 goreplay 核心源码分析> ...
- 搭建sock5代理
安装 下载脚本 wget --no-check-certificate https://raw.github.com/Lozy/danted/master/install.sh -O install. ...
- 国内主流大数据厂商太多不知道怎么选?Smartbi满足你的需求
目前的BI市场上有很多大数据的厂商,这也让许多客户眼花缭乱,不知如何下手.比如国内的亿信华辰跟国外的Tableau,QLK, PowerBI 都有非常多便于分析的可视化工具,但是在数据处理分析的功能 ...
- Pytorch AdaptivePooing操作转Pooling操作
Pytorch AdaptivePooing操作转Pooling操作 多数的前向推理框架不支持AdaptivePooing操作,此时需要将AdaptivePooing操作转换为普通的Pooling操作 ...
- 【C#基础概念】字节顺序(大端、小端)
字节顺序,又称端序或尾序(英語:Endianness),在计算机科学领域中,指電腦記憶體中或在数字通信链路中,组成多字节的字的字节的排列顺序. 例如假设上述变量x类型为int,位于地址0x100处,它 ...
- C# Event 内核构造 |EventWaitHandle、AutoResetEvent、 ManualResetEvent
EventWaitHandle 继承:Object->WaitHandle-> EventWaitHandle派生:System.Threading.AutoResetEvent\Syst ...