# bzoj4671: 异或图

## Description

G2 中的出现次数之和为 1, 那么边 (u, v) 在 G 中, 否则这条边不在 G 中.

## Input

Algorithm 1 Print a graph G = (V, E)
for i = 1 to n do
for j = i + 1 to n do
if G contains edge (i, j) then
print 1
else
print 0
end if
end for
end for

$2 ≤ n ≤ 10,1 ≤ s ≤ 60.$

## Output

$f(i)=\sum_{j=i}^n g(j) * S(j,i)$

$g(i)=\sum_{j=i}^n f(j) * s(j,i) * (-1)^{j-i}$

$g(1)=\sum_{i=1}^n f(i) * s(i,1) * (-1)^{i-1}$

#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
int x;
char c;
int f=1;
while((c=getchar())!='-' && (c<'0' || c>'9'));
if(c=='-') c=getchar(),f=-1;
x=c^'0';
while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
return x*f;
}
ll x;
char c;
ll f=1;
while((c=getchar())!='-' && (c<'0' || c>'9'));
if(c=='-') c=getchar(),f=-1;
x=c^'0';
while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
return x*f;
}
const int maxm=60+1,maxn=10+1;
int n,m;
char s[maxm];
bool E[maxm][maxn][maxn];
int p[maxn],id[maxn][maxn];
ll a[maxm];
ll fac[maxm],ans;
struct point{
int x,y;
}b[maxm];
void dfs(int x,int num){
if(x>n){
memset(a,0,sizeof(a));
int res=0,tmp=-1;
REP(i,1,n) REP(j,i+1,n) if(p[i]!=p[j]) b[++tmp]=(point){i,j};
REP(i,1,m){
ll nw=0;
REP(j,0,tmp) if(E[i][b[j].x][b[j].y]) nw|=(1ll<<(ll)j);
DREP(j,tmp,0)
if(nw&(1ll<<(ll)j)){
if(a[j]) nw^=a[j];
else{
a[j]=nw;res++;
break;
}
}
}
/*      REP(i,1,n) REP(j,i+1,n){
if(p[i]==p[j]) continue;
ll nw=0;
REP(k,1,m) if(E[k][i][j]) nw|=(1ll<<(ll)(k-1));
DREP(k,m-1,0)
if(nw&(1ll<<(ll)k)){
if(a[k]) nw^=a[k];
else{
a[k]=nw;res++;
break;
}
}
}
*/
ans+=fac[num-1]*(1ll<<(ll)(m-res));
return;
}
REP(i,1,num+1) p[x]=i,dfs(x+1,max(num,i));
}
int main(){
#ifndef ONLINE_JUDGE
freopen("cnt.in","r",stdin);
freopen("cnt.out","w",stdout);
#endif
scanf("%s",s+1);int len=strlen(s+1);
while(n*(n-1)/2<len) ++n;len=0;
REP(i,1,n)
REP(j,i+1,n)
E[1][i][j]=s[id[i][j]=++len]-'0';
REP(k,2,m){
len=0;scanf("%s",s+1);
REP(i,1,n) REP(j,i+1,n)  E[k][i][j]=s[++len]-'0';
}
fac[0]=1;
REP(i,1,n) fac[i]=-fac[i-1]*i;
dfs(1,0);
printf("%lld\n",ans);
return 0;
}
posted @ 2018-03-29 17:53  zhou888  阅读(...)  评论(...编辑  收藏