题意:
思路:状压
#include <stdio.h>
#include <string.h>
const int mod = 100000000;
int dp[15][1 << 15],sta[15];
int main(void)
{
int m,n,i,j,base,k,ans,t;
scanf("%d %d",&m,&n);
for(i = 1; i <= m; i++) {
base = 1;
for(j = 0; j < n; j++) {
scanf("%d",&t);
if(t) sta[i] += base;
base *= 2;
}
}
dp[0][0] = 1;
for(i = 1; i <= m; i++) {
for(j = 0; j < (1 << n); j++) { //枚举第i行的状态
if((j & sta[i]) != j) continue; //第i行的状态不能与题目要求矛盾
if(j & (j << 1)) continue; //第i行不能有相邻
for(k = 0; k < (1 << n); k++) { //枚举第i-1行的状态
if(j & k) continue;//第i-1行与第i行不能有相邻
dp[i][j] += dp[i - 1][k];
dp[i][j] %= mod;
}
}
}
ans = 0;
for(i = 0; i < (1 << n); i++)
ans = (ans + dp[m][i]) % mod;
printf("%d\n",ans);
return 0;
}