forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI.cpp
More file actions
65 lines (57 loc) · 1.46 KB
/
I.cpp
File metadata and controls
65 lines (57 loc) · 1.46 KB
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
#include <bits/stdc++.h>
using namespace std;
long long f[2][1 << 8][1 << 8];
int m, n;
int bit(int x)
{
return 1 << x;
}
int solidMask(int mask)
{
int prev = -1, res = 0;
mask = bit(n) | (bit(n) - 1 - mask);
for (int i = 0; i <= n; i++)
if (mask & bit(i))
{
if ((i - prev - 1) % 2) return -1;
for (int j = prev + 1; j < i; j += 2)
res |= bit(j);
prev = i;
}
return res;
}
int main()
{
ios::sync_with_stdio(0);
freopen("solid.in", "r", stdin);
freopen("solid.out", "w", stdout);
cin >> n >> m;
for (int mask = 0; mask < bit(n); mask++)
{
int solid = solidMask(mask);
if (solid < 0) continue;
f[0][mask][solid] = 1;
}
int z = 0;
for (int i = 1; i < m; i++)
for (int j = 0; j < n; j++)
{
z ^= 1;
memset(f[z], 0, sizeof f[z]);
for (int mask = 0; mask < bit(n); mask++)
for (int solid = 0; solid < bit(n - 1); solid++)
{
long long &ways = f[z ^ 1][mask][solid];
if (!ways) continue;
if (!j && mask == bit(n) - 1) continue;
if (mask & bit(0))
{
f[z][mask >> 1][solid] += ways;
if (j && !(mask & bit(n - 1)))
f[z][(mask >> 1) | bit(n - 1) | bit(n - 2)][solid | bit(j - 1)] += ways;
}
else f[z][mask >> 1 | bit(n - 1)][solid] += ways;
}
}
cout << f[z][bit(n) - 1][bit(n - 1) - 1] << endl;
}