-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOJ-3254-Corn Fields.txt
96 lines (86 loc) · 1.28 KB
/
POJ-3254-Corn Fields.txt
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//POJ - 3254-Corn Fields
#include "stdio.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 100000000;
const int N = 13;
const int M = 13;
int map[M];
int states[1<<(N-2)];
int dp[M][1<<(N-2)];
int top;
bool ok(int i)
{
if(!(i & i<<1))
return true;
return false;
}
void init(int n)
{
for(int i=0; i<(1<<n); i++)
{
if(ok(i))
states[++top] = i;
}
}
bool fit(int i, int k)
{
if(i & k)
return false;
return true;
}
int main()
{
int m, n;
while(scanf("%d%d", &m, &n) != EOF)
{
memset(dp, 0, sizeof(dp));
top=0;
int num;
for(int i=1; i<=m; i++)
{
map[i]=0;
for(int j=1; j<=n; j++)
{
scanf("%d", &num);
if(num==0)
map[i] += 1<<(n-j);
}
}
init(n);
for(int i=1; i<=top; i++)
{
if(fit(states[i], map[1]))
dp[1][i]=1;
}
for(int i=2; i<=m; i++)
{
for(int j=1; j<=top; j++)
{
if(!fit(states[j], map[i]))
continue;
for(int k=1; k<=top; k++)
{
if(!fit(states[k], map[i-1]))
continue;
if(states[j]&states[k])
continue;
dp[i][j] += dp[i-1][k];
}
}
}
int ans=0;
for(int i=1; i<=top; i++)
{
ans += dp[m][i];
ans %= MOD;
}
printf("%d\n", ans);
}
return 0;
}