UOJ 185【ZJOI2016】小星星
来源:互联网 发布:mysql exists in 效率 编辑:程序博客网 时间:2024/06/02 16:40
求点数相同的一个无向图与一棵树有多少种不同的映射,使得树的边集为图的边集的子集。
首先orz吨爷
可以说是因为吨爷才去学的子集卷积(vfleaking)==结果过不掉
这样写树形dp感觉还行吧(燃烧的内存),好像这几次利用单调性什么的,最后都没用到+卷积,只是用or卷积,以后会遇上吗?
#include <set>#include <ctime>#include <queue>#include <cstdio>#include <bitset>#include <cctype>#include <bitset>#include <cstdlib>#include <cassert>#include <cstring>#include <iostream>#include <algorithm>#define inf (1<<30)#define INF (1ll<<62)#define fi first#define se second#define rep(x,s,t) for(register int x=s,t_=t;x<t_;++x)#define per(x,s,t) for(register int x=t-1,s_=s;x>=s_;--x)#define prt(x) cout<<#x<<":"<<x<<" "#define prtn(x) cout<<#x<<":"<<x<<endl#define travel(x) for(int I=last[x],to;to=e[I].to,I;I=e[I].nxt)#define pb(x) push_back(x)#define hash asfmaljkg#define rank asfjhgskjf#define y1 asggnja#define y2 slfvmusing namespace std;typedef long long ll;typedef pair<int,int> ii;template<class T>void sc(T &x){ int f=1;char c;x=0; while(c=getchar(),c<48)if(c=='-')f=-1; do x=x*10+(c^48); while(c=getchar(),c>47); x*=f;}template<class T>void nt(T x){ if(!x)return; nt(x/10); putchar(x%10+'0');}template<class T>void pt(T x){ if(x<0)putchar('-'),x=-x; if(!x)putchar('0'); else nt(x);}template<class T>void ptn(T x){ pt(x);putchar('\n');}template<class T>void pts(T x){ pt(x);putchar(' ');}template<class T>inline void Max(T &x,T y){if(x<y)x=y;}template<class T>inline void Min(T &x,T y){if(x>y)x=y;}const int maxn=18;int n,m;int b[maxn][maxn];int last[maxn],ecnt;struct Edge{ int to,nxt;}e[maxn<<1];void ins(int u,int v){ e[++ecnt]=(Edge){v,last[u]}; last[u]=ecnt;}ll dp[maxn][maxn][1<<maxn];ll dp2[1<<maxn];void ormul(ll *a,ll *b,ll *c){ static ll A[1<<maxn],B[1<<maxn]; rep(i,0,1<<n)A[i]=a[i],B[i]=b[i]; rep(i,0,n)rep(j,1,1<<n) if(j>>i&1){ A[j]+=A[j^1<<i]; B[j]+=B[j^1<<i]; } rep(i,0,1<<n)c[i]=A[i]*B[i]; rep(i,0,n)rep(j,1,1<<n) if(j>>i&1)c[j]-=c[j^1<<i];}int cnt=0;void dfs(int x,int f){ travel(x)if(to!=f)dfs(to,x); rep(i,0,n){ dp[x][i][1<<i]=1; travel(x)if(to!=f){ rep(k,0,1<<n)dp2[k]=0; rep(j,0,n)if(b[i][j]) rep(k,0,1<<n)dp2[k]+=dp[to][j][k]; ormul(dp[x][i],dp2,dp[x][i]); } }}int main(){// freopen("pro.in","r",stdin);// freopen("ex_star2.in","r",stdin);// freopen("chk.out","w",stdout); sc(n);sc(m); rep(i,0,m){ int u,v; sc(u);sc(v);--u;--v; b[u][v]=b[v][u]=true; } rep(i,1,n){ int u,v; sc(u);sc(v);--u;--v; ins(u,v);ins(v,u); } dfs(0,-1); ll ans=0;int all=(1<<n)-1; rep(i,0,n)ans+=dp[0][i][all]; ptn(ans); return 0;}
看了StilWell的代码之后发现:
小范围直接卷会快很多(甚至都可以直接AC了)
不仅仅只有vfk版卷积
有一个更通用的构造,FWT(Fast Walsh-Hadamard Transform)(zhuohan123,Picks)
tfxor(A)=(tfxor(A0+A1),tfxor(A0−A1))utfxor(A)=(utfxor(A0+A12),utfxor(A0−A12))
tfand(A)=(tfand(A0+A1),tfand(A1))utfand(A)=(utfand(A0−A1),utfand(A1))
tfor(A)=(tfor(A0),tfor(A1+A0))utfor(A)=(utfor(A0),utfor(A1−A0))
笔记:
考虑一位时,
就是容斥==
然后很多位的的时候再来个大容斥
这就是FWT,用来解决位运算的卷积的构造
0 0
- UOJ 185【ZJOI2016】小星星
- [UOJ#185][ZJOI2016] 小星星
- BZOJ 4455 & UOJ 185 [ZJOI2016]小星星
- [容斥 状压DP 树形DP] BZOJ 4455 [Zjoi2016]小星星 & UOJ #185 【ZJOI2016】小星星
- [ZJOI2016]小星星
- [BZOJ4455][Zjoi2016]小星星
- 【bzoj4455】[Zjoi2016]小星星
- bzoj 4455: [Zjoi2016]小星星
- BZOJ4455 [Zjoi2016]小星星
- BZOJ 4455: [Zjoi2016]小星星
- 4455: [Zjoi2016]小星星
- bzoj4455 ZJOI2016 小星星
- 【bzoj3349】[Zjoi2016]小星星
- bzoj 4455: [Zjoi2016]小星星
- bzoj 4455: [Zjoi2016]小星星
- UOJ 184 [ZJOI2016]旅行者
- [zjoi2016][小星星][容斥]解题报告
- [bzoj4573][UOJ#195][ZJOI2016]大森林
- 开源框架整理
- 2097 Sky数
- HTML <!--注释标签的插入,不显示在浏览器中-->
- 作弊的发牌者
- 同时安装Java 1.7和1.8
- UOJ 185【ZJOI2016】小星星
- Datagridview绑定dataset数据
- hdu 2176 取(m堆)石子游戏 (Nim博弈求第一步取法)
- uva1592-Database
- ES集群读写分离
- servlet使用
- hdoj-2544
- 致雅嵌入式工作室——为Wi-Fi小车增加密码设置功能
- 在Spydroid-ipcamera基础上做推流的实现之一