题目:Corn Fields
思路:记忆化搜索+位运算 。
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cstring>
#include <map>
using namespace std;long long m,n;
long long b[5000]= {0};
long long f[20][5000]= {0};
long long d[5000]= {0};long long dfs(long long step,long long state) {if(step==n) return 1;long long x=0;for(long long i=0; i<(1<<m); i++) {if(d[i]&&!(i&state)&&(i|b[step])==b[step]) {if(f[step+1][i]) {x+=f[step+1][i];continue;}long long y=dfs(step+1,i);f[step+1][i]=y;x=x+y;}}return x;
}bool judge(long long x) {long long t=-1,y;for(long long i=0; i<m; i++) {y=x%2;x/=2;if(y==t&&y==1) return false;t=y;}return true;
}int main() {scanf("%lld%lld",&n,&m);for(long long i=0; i<(1<<m); i++) {if(judge(i)) d[i]=true;}long long a[20][20]= {0};for(long long i=0; i<n; i++) {long long x=0,y=1;for(long long j=0; j<m; j++) {scanf("%lld",&a[i][j]);x+=y*a[i][j];y*=2;}b[i]=x;}printf("%lld",dfs(0,0)%100000000);return 0;
}