AcWing 291. 蒙德里安的梦想python3
原题链接
中等
作者:
xanxus1111
,
2020-07-12 20:45:50
,
所有人可见
,
阅读 520
N = 12
M = 1 << N
f = [[0]*M for _ in range(N)]
st = [False]*M
if __name__ == "__main__":
n,m = map(int, input().split())
while n or m:
#初始化数组
for i in range(len(f)):
for j in range(len(f[0])):
f[i][j] = 0
for i in range(len(st)):
st[i] = False
#预处理
for i in range(1<<n):
st[i] = True
cnt = 0
for j in range(n):
if i >> j & 1:
if cnt & 1:
st[i] = False
cnt = 0
else:cnt += 1
if cnt & 1:st[i] = False
#
f[0][0] = 1
for i in range(1, m+1):
for j in range(1<<n):
for k in range(1<<n):
if j&k == 0 and st[j|k]:
f[i][j] += f[i-1][k]
print(f[m][0])
n,m = map(int, input().split())