include iostream include vector using namespace std const int vector v

 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
#include<iostream>
#include <vector>
using namespace std;
const int w = 4, h = 4;
vector<vector<long long> > dp(w +1, vector<long long>(1<<h));
vector<bool> precalc;
bool calc(int k)
{
int count = 0;
int c = 0;
for(int i = 0; i < 1<<h; i++)
{
if(k&(1<<i))
{
count++;
c++;
}
else
{
if(c%2 != 0)
return false;
else
c = 0;
}
}
if(count%2 == 0)
return true;
else
return false;
}
int main()
{
dp[0][0] = 1;
for(int k = 0; k < (1<<h); k++)
{
precalc.push_back(calc(k));
}
for(int i = 0; i < w; ++i)
{
for(int m1 = 0; m1 < (1<<h); m1++)
{
if(dp[i][m1] > 0)
{
for(int m2 = 0; m2 < (1<<h); m2++)
{
if((m1 & m2) == 0 && precalc[m1|m2])
{
dp[i+1][m2]+=dp[i][m1];
}
}
}
}
}
cout << dp[w][0] << endl;
}