#include "iostream"
#include "algorithm"
#include "cstdio"
#include "cstring"
#include "cmath"
#include "cstdlib"
#include "iomanip"
#include "string"
#include "queue"
#include "vector"
#include "set"
#include "map"
#include "stack"
#include "cmath"
#define INF 0xFFFFFFF
using namespace std;
#define N 13
#define M 1<<13
int i,j,k,m,n,x;
int maps[M],dp[N][M],st[M];
bool judge1(int x)
{
return (x&(x<<1));
}
bool judge2(int i,int j)
{
return (maps[i]&st[j]);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,0,sizeof(dp));
memset(st,0,sizeof(st));
memset(maps,0,sizeof(maps));
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
scanf("%d",&x);
if(x==0)
maps[i]|=(1<<(j-1));//用map存储数组每一行的状态数(10进制)例如:用7表示该行//111,5表示101
}
int k=0;
for(i=0;i<1<<m;i++)//st矩阵存储例如:0,1,2,4,5,9,10相对的二进制没有相邻的1的数
if(!judge1(i))
st[k++]=i;
for(i=0;i
if(!judge2(1,i))
dp[1][i]=1;//初始化递归数组
for(i=2;i<=n;i++)
for(j=0;j
{
if(judge2(i,j))//判断第i行能不能放牛也就是有没有相邻的1
continue;
for(int s=0;s
{
if(judge2(i-1,s))//判断与上一行是否上下满足没有相邻的1
continue;
if(!(st[j]&st[s]))//判断本行是否满足没有相邻的1
dp[i][j]+=dp[i-1][s];
}
}
int ans=0;
for(i=0;i
{
ans+=dp[n][i];
ans%=100000000;
}
printf("%d\n",ans);
}
return 0;
}
poj3245
最新推荐文章于 2020-06-19 10:47:42 发布