[HZOI 2015] 有标号的DAG计数 I

设\(f_i\)为\(i\)个点时的DAG图,(不必联通)

考虑如何转移,由于一个DAG必然有至少一个出度为\(0\)的点,所以我们钦定多少个出度为\(0\)的点转移。

考虑如何保证没有环,钦定完出度为\(0\)的点后,这些点就等着被连接了。还剩下一些点,这些点只要不构成环就好了,就是个子结构,访问以前的DP数组就好了。

\[ {i\choose j}2^{j\times (i-j)}dp_{i-j}
\]

这样转移显然有方案重复的情况,因为如此计数就破坏了钦定,出度为\(0\)点可能更多!(我们不加限制的枚举\(j(i-j)\)条边是否存在)。

考虑一种方案出现了多少次,很显然出现的分布是这样的:

\[{i \choose 1}+{i \choose 2}+{i \choose 3}\dots
\]

借鉴一下[【题解】HAOI2018]染色(NTT+容斥/二项式反演)(怎么又是你),直接乘上一个\((-1)^?\)就就容斥掉了,试一试就发现是\((-1)^{j+1}\)

转移是:

\[dp_i=\sum_{j=1}^i {i\choose j}2^{j\times (i-j)}dp_{i-j}(-1)^{j+1}
\]

或者学习神Itst的神仙待定系数法

设枚举的出度为\(0\)的点的个数为i时的容斥系数为\(f_i\),那么一个实际上存在\(x\)个出度为0的点的DAG的贡献就是\(\sum\limits_{i=1}^x \binom{x}{i} f_i = 1\),不难由二项式定理知道\(fi=(−1)^{i−1}\)

orz orz

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
} const int maxn=5e3+5;
const int mod=10007;
int c[maxn][maxn];
int dp[maxn];
int bin[maxn*maxn]; int main(){
freopen("DAG.in","r",stdin);
freopen("DAG.out","w",stdout);
int n=qr();
bin[0]=1;dp[0]=1;
for(register int t=0;t<=n;++t){
c[t][0]=1;
for(register int i=1;i<=t;++i){
c[t][i]=(c[t-1][i-1]+c[t-1][i])%mod;
}
}
for(register int t=1;t<=n*n;++t) bin[t]=(bin[t-1]<<1)%mod; for(register int t=1;t<=n;++t){
for(register int i=1,d;i<=t;++i){
d=mod-c[t][i]*bin[i*(t-i)]%mod*dp[t-i]%mod;
if(i&1) d=mod-d;
dp[t]=(dp[t]+d)%mod;
}
}
printf("%d\n",dp[n]);
return 0;
}

最新文章

  1. GConf error:Failed to contact configuration server
  2. Dapper学习 - Dapper的基本用法(三) - CUD
  3. 修改efi分区
  4. 百度地图API使用
  5. 【Android】ADB常用指令与logcat日志(转)
  6. C++程序员笔试复习概要(一)
  7. [Redux] Generating Containers with connect() from React Redux (FooterLink)
  8. 移动端 延迟加载echo.js的使用
  9. pyqt样式表语法笔记(下)--原创
  10. 神奇的background
  11. hdu_1698Just a Hook(线段树)
  12. [USACO17FEB]Why Did the Cow Cross the Road I S
  13. go [第一篇]初识
  14. sysbench对MySQL的压测
  15. 常用的几条sql语句
  16. day 28 面向对象 三种特性之一 多态 鸭子类型 反射(反省)
  17. 团队项目alpha冲刺
  18. 第一次Spring总结
  19. Python实现C代码统计工具(三)
  20. 关于vector变量的size,是一个无符号数引发的bug。LeetCode 3 sum

热门文章

  1. 2019-8-31-dotnet-使用-MessagePack-序列化对象
  2. oracle使用DECODE函数来减少处理时间
  3. @noi.ac - 493@ trade
  4. 如何编程实现快速获取一个整型数中的bit流中1的个数
  5. ThinkPHP5.1接收post、get参数
  6. Java Annotation详解(二): 反射和Annotation
  7. 2019-9-9-dotnet-获取本机-IP-地址方法
  8. java final域
  9. Python--day43--增删改查补充和limit以及order by
  10. H3C 基于ACL的包过滤技术