【BZOJ4671】—异或图(斯特林反演+线性基)

传送门

考虑枚举连通块
强制不同连通块间没边
用斯特林反演,乘(1)tot1(tot1)!(-1)^{tot-1}(tot-1)!
得到一个连通块的情况

只需要对于每个图的每个边看做一个二进制位
sizsiz为线性基的数的个数
一种划分的方案数就是2ssiz2^{s-siz}

#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ob==ib)?EOF:*ib++;
}
#define gc getchar
inline int read(){
    char ch=gc();
    int res=0,f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
#define ll long long
#define re register
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cs const
#define bg begin
const int mod=1e9+7;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline void Add(int &a,int b){a=add(a,b);}
inline int dec(int a,int b){return a>=b?a-b:a-b+mod;}
inline void Dec(int &a,int b){a=dec(a,b);}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,a=mul(a,a))(b&1)?(res=mul(res,a)):0;return res;}
inline void chemx(int &a,int b){a<b?a=b:0;}
inline void chemn(int &a,int b){a>b?a=b:0;}
cs int N=12,S=65;
int n,s;
char str[N*N];
int e[S][N][N],bel[N];
ll ans,fac[N];
ll bas[S];
inline void calc(int tot){
    int siz=0;
    memset(bas,0,sizeof(bas));
    for(int i=1;i<=s;i++){
        ll tt=0,num=0;
        for(int u=1;u<=n;u++)
        for(int v=u+1;v<=n;v++)
        if(bel[u]!=bel[v])tt+=(1ll*e[i][u][v])<<(num++);
        for(int t=num-1;~t;t--){
            if(tt&(1ll<<t)){
                if(bas[t])tt^=bas[t];
                else {bas[t]=tt,siz++;break;}
            }
        }
    }
    if(tot&1)ans+=(1ll<<(s-siz))*fac[tot-1];
    else ans-=(1ll<<(s-siz))*fac[tot-1];
}
void dfs(int pos,int siz){
    if(pos==n+1)return calc(siz);
    for(int i=1;i<=siz;i++)bel[pos]=i,dfs(pos+1,siz);
    bel[pos]=siz+1,dfs(pos+1,siz+1);
}
int main(){
    s=read();
    for(int i=1;i<=s;i++){
        scanf("%s",str+1);
        int len=strlen(str+1),pos=0;
        n=(1+sqrt(1+8*len))/2;
        for(int u=1;u<=n;u++)
        for(int v=u+1;v<=n;v++)
        e[i][u][v]=str[++pos]-'0';
    }
    fac[0]=1;
    for(int i=1;i<=10;i++)fac[i]=fac[i-1]*i;
    dfs(1,0);
    cout<<ans;
}

posted @ 2019-09-10 18:07  Stargazer_cykoi  阅读(107)  评论(0编辑  收藏  举报