The meaning of the question: There is a field of n*m, 0 means barren, no things can be planted, 1 means fertile, ask, if there is no public border between the two land to be planted, and how many kinds of plans cannot be planted on barren land , Not planting at all is also a solution.
Idea: dp[i][j], which represents the number of land plans with the state of planting land in the i-th row, first preprocess the state of the first row, that is, dp[1] [1-n], the transfer is:
dp[ i ][ j] += dp[ i-1] [k ], (k is no public side with j && k internal land has no public side).
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9,maxn = 15;
int dp[maxn][1<<maxn],a[maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j = m-1;j>=0;j--)
{
int x;
scanf("%d",&x);
if(x == 0)a[i] += (1<<j);
}
for(int s = 0; s < 1<<m; s++)
if((s&a[1])==0 && (s<<1&s)==0 && (s>>1&s)==0)dp[1][s] = 1;
for(int i=2;i<=n;i++)
for(int s=0;s<1<<m;s++)
for(int s0 = 0; s0 < 1<<m; s0++)
{
if(dp[i-1][s] && (s0&a[i]) == 0 && (s0&s) == 0 && (s0<<1&s0)==0 && (s0>>1&s0)==0)
dp[i][s0] += dp[i-1][s],dp[i][s0] %= mod;
}
ll sum = 0;
for(int i=0;i<1<<m;i++)sum += dp[n][i],sum%=mod;
printf("%d\n",sum);
}