https://ac.nowcoder.com/acm/contest/12482/D
Question meaning: https://blog.csdn.net/zstuyyyyccccbbbb/article/details/115171072 On the basis of the original question, some points cannot be placed.
Idea: Combine these non-placeable ones into the pre-processed st[]. Here we need to open st[][] into two dimensions to record the feasibility of the state of the i-th column and j.
detail:
1. Convert non-storable into binary number accumulation (denoted as temp), traverse all the processes [state & temp], if = = 1, it means that the non-storable state is included, and it is necessary to mark it as invalid
2. Due to the limitation of non-storage, it affects the feasibility of the original single row/single row.
Such as:
temp: 0 0 1 0 1 0 0 (the one marked with 1 is X)
j: 0 1 0 1 0 0 0
In this way, directly judging the continuous 0 parity of j will cause problems, so x==(j|temp), and then the continuous 0 parity judgment with x, and the result will mark the state of j
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=13;
typedef int LL;
typedef pair<LL,LL>P;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
bool st[maxn][1<<maxn];///每一列的可行状态
long long dp[maxn][1<<maxn];
bool map1[maxn][maxn];
int main(void)
{
LL n,m,k;
while(scanf("%d%d%d",&n,&m,&k)!=0){
if(n==0&&m==0&&k==0) break;
memset(map1,0,sizeof(map1));
for(LL i=1;i<=k;i++){
LL x,y;
scanf("%d",&x);scanf("%d",&y);
map1[x][y]=true;
}
for(LL i=1;i<=m;i++){///枚举每一列
LL temp=0;
for(LL j=1;j<=n;j++){///该列的每一行
if(map1[j][i]) temp+=(1<<(j-1));
}
for(LL j=0;j<(1<<n);j++){///该列的全状态
st[i][j]=true;
if( j&(temp) ) {st[i][j]=false;continue;}
LL x=j|temp;///细节
LL cnt=0;
for(LL k=1;k<=n;k++){
if( ( 1<<(k-1) ) &x ){
if(cnt&1){
st[i][j]=false;break;
}
else cnt=0;
}
else cnt++;
}
if(cnt&1) st[i][j]=false;
}
}
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(LL i=1;i<=m;i++){
for(LL j=0;j<(1<<n);j++){
for(LL k=0;k<(1<<n);k++){
if((j&k)==0&&st[i][j|k]==true){
dp[i][j]+=dp[i-1][k];
}
}
}
}
printf("%lld\n",dp[m][0]);
}
return 0;
}