标签:
状压DP。位运算真是弱项
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 #include<queue> 6 #define inc(i,l,r) for(int i=l;i<=r;i++) 7 #define dec(i,l,r) for(int i=l;i>=r;i--) 8 #define link(x) for(edge *j=h[x];j;j=j->next) 9 #define mem(a) memset(a,0,sizeof(a)) 10 #define inf 1e9 11 #define ll long long 12 #define succ(x) (1<<x) 13 #define NM 13 14 using namespace std; 15 int read(){ 16 int x=0,f=1;char ch=getchar(); 17 while(!isdigit(ch)){if(ch==‘-‘)f=-1;ch=getchar();} 18 while(isdigit(ch))x=x*10+ch-‘0‘,ch=getchar(); 19 return x*f; 20 } 21 int a[NM],b[succ(NM)],d[NM][succ(NM)],n,m,ans,s; 22 int main(){ 23 n=read();m=read(); 24 inc(i,1,n) 25 inc(j,1,m) 26 if(!read())a[i]+=succ(j-1); 27 inc(t,0,succ(m)-1) 28 if((t&(t<<1))==0){ 29 b[++s]=t; 30 if(!(t&a[1])) 31 d[1][t]=1; 32 } 33 inc(i,2,n){ 34 inc(t,1,s){ 35 if(b[t]&a[i])continue; 36 inc(v,1,s) 37 if(!(b[v]&b[t])) 38 d[i][b[t]]+=d[i-1][b[v]]; 39 // printf("%d %d\n",b[t],d[i][b[t]]); 40 } 41 } 42 inc(t,0,succ(m)-1)(ans+=d[n][t])%=100000000; 43 printf("%d\n",ans); 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/onlyRP/p/5055440.html