# [XOR最小生成树 期望 DP] BZOJ 4770 图样

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;

const int P=258280327;
const int N=51,M=9;
const int MP=10000;

ll C[N][N],pw[MP];

inline void Pre(int n){
C[0][0]=1;
for (int i=1;i<=n;i++){
C[i][0]=1;
for (int j=1;j<=i;j++)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
}
pw[0]=1;
for (int i=1;i<MP;i++) pw[i]=(pw[i-1]<<1)%P;
}

inline ll Pow(ll a,int b){
ll ret=1; for (;b;b>>=1,a=a*a%P) if (b&1) ret=ret*a%P; return ret;
}

int _p[N][N][M][1<<M];
bool fp[N][N][M][1<<M];

inline ll p(int S,int T,int m,int K){
if (fp[S][T][m][K]) return _p[S][T][m][K];
if (K>=(1<<m)) return 0;
if (m==1) return K==1?2:pw[S+T];
if (K<=0) return pw[(S+T)*m];
ll ans=0;
for (int i=1;i<S;i++)
for (int j=1;j<T;j++)
ans+=(C[S][i]*C[T][j]%P)*(p(i,j,m-1,K)*p(S-i,T-j,m-1,K)%P)%P;
for (int j=1;j<T;j++)
ans+=(C[T][j]*p(S,j,m-1,K)%P*pw[(m-1)*(T-j)]%P)<<1;
for (int i=1;i<S;i++)
ans+=(C[S][i]*p(i,T,m-1,K)%P*pw[(m-1)*(S-i)]%P)<<1;
ans+=p(S,T,m-1,K-(1<<(m-1)))<<1;
ans+=p(S,T,m-1,K)<<1;
return fp[S][T][m][K]=1,_p[S][T][m][K]=ans%P;
}

int _g[N][N][M];
bool fg[N][N][M];

inline ll g(int S,int T,int m){
if (!m) return 0;
if (fg[S][T][m]) return _g[S][T][m];
ll ret=0;
for (int k=1;k<(1<<m);k++)
ret+=p(S,T,m,k);
return fg[S][T][m]=1,_g[S][T][m]=ret%P;
}

int n,m;
ll f[M][N];

int main(){
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
for (int i=1;i<=m;i++)
for (int j=1;j<=n;j++){
for (int k=1;k<j;k++)
f[i][j]+=C[j][k]*(pw[(j-k)*(i-1)]*f[i-1][k]%P+pw[k*(i-1)]*f[i-1][j-k]%P+g(k,j-k,i-1)+pw[(j+1)*(i-1)])%P;
(f[i][j]+=(f[i-1][j]<<1)%P)%=P;
}
printf("%d\n",f[m][n]*Pow(pw[m*n],P-2)%P);
return 0;
}


• 评论

3

• 上一篇
• 下一篇