Corn Fields
time limit per test 1 second memory limit per test 256 megabytes
Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can’t be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.
Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.

传送门:POJ3254

Input

Line 1: Two space-separated integers: M and N Lines 2.. M+1: Line i+1 describes row i of the pasture with N space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)

Output

Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.

Sample Input

1
2
3
2 3
1 1 1
0 1 0

Sample Output

1
9

题解

状压dp 注意代码中有连续的1的判断和x真包含于y的判断 y取反再与x为零
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;  
import java.util.*;
public class Main {
static int[][]maze;
static int[]row;
static int m;
static int n;
static int mod=100000000;
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
m=sc.nextInt();
n=sc.nextInt();
maze=new int[m][n];
row=new int[m];
for(int i=0;i<m;i++){
int temp=0;
for(int j=0;j<n;j++){
maze[i][j]=sc.nextInt();
temp=temp*2+1^maze[i][j];
}
row[i]=temp;
}
long[][]dp=new long[m][1<<n];
for(int i=0;i<m;i++){
for(int j=0;j<(1<<n);j++){
if(rowok(i,j)){
if(i==0)dp[0][j]=1;
else{
for(int k=0;k<(1<<n);k++){
if((j&k)==0)
dp[i][j]=(dp[i][j]%mod+dp[i-1][k]%mod)%mod;
}
}
}
}
}
long sum=0;
for(int i=0;i<(1<<n);i++){
sum=(sum%mod+dp[m-1][i]%mod)%mod;
}
pw.println(sum%mod);
pw.flush();
}
}
static boolean rowok(int i,int j){
if(((row[i]&j)!=0)||((j&(j<<1))!=0)) //(j&(j<<1))!=0存在连续的1
return false;
return true;
}
}