前言
感觉是简单DP。
肯定是状压。
然后你只需要想到按照mex划分即可。
题意
一个有向无环图,求有多少边集的子集组成的图,使得sg1 xor sg2>0
DP
正难则反,考虑使1和2sg值相等。
设dps表示只考虑s这个点集的答案(可以不包含1和2)。
我们把s划分为A和B,其中B是mex最小的点集,那么A中每个点至少要连向B一条边,B中点可以随意连向A,剩余方案是dpA。
我们当然不允许1和2被分离到A和B中,必须同时在A或同时在B。
然后可以预处理gi,s表示i连向s至少一条边方案数,以及fi,s表示i连向s的边数,方案计算可以做到o(n)。
枚举集合以及子集总复杂度是3n。
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int mo=1000000007;
bool bz[15+5][15+5];
int two[300],id[1<<17];
int f[15+5][1<<17],g[15+5][1<<17],dp[1<<17];
int i,j,k,l,r,s,t,n,m,ans;
int lowbit(int x){
return x&-x;
}
int main(){
scanf("%d%d",&n,&m);
fo(i,1,n) id[1<<(i-1)]=i;
two[0]=1;
fo(i,1,m) two[i]=(ll)two[i-1]*2%mo;
fo(i,1,m){
scanf("%d%d",&j,&k);
bz[j][k]=1;
}
fo(i,1,n)
fo(s,1,(1<<n)-1)
f[i][s]=f[i][s-lowbit(s)]+bz[i][id[lowbit(s)]];
fo(i,1,n)
fo(s,1,(1<<n)-1){
k=id[lowbit(s)];
if (!bz[i][k]) g[i][s]=g[i][s-lowbit(s)];
else g[i][s]=((ll)g[i][s-lowbit(s)]*2%mo+1)%mo;
}
fo(s,1,(1<<n)-1){
//if (!((s&1)&&(s&2))) continue;
dp[s]=1;
t=(s-1)&s;
while (t){
if (((s^t)&1)&&(t&2)){
t=(t-1)&s;
continue;
}
if (((s^t)&2)&&(t&1)){
t=(t-1)&s;
continue;
}
r=1;
fo(i,1,n)
if ((t&(1<<(i-1)))) r=(ll)r*g[i][s^t]%mo;
l=0;
fo(i,1,n)
if (((s^t)&(1<<(i-1)))) l+=f[i][t];
r=(ll)r*two[l]%mo;
(dp[s]+=(ll)dp[t]*r%mo)%=mo;
t=(t-1)&s;
}
}
ans=(two[m]-dp[(1<<n)-1])%mo;
(ans+=mo)%=mo;
printf("%d\n",ans);
}