# 多米诺瓷砖的数量

9

``````|--    |||    --|
|--    |||    --|
``````

``````1,  9 -> 0
2,  2 -> 2
2,  3 -> 3
4,  4 -> 36
4,  6 -> 281
6,  6 -> 6728
7, 10 -> 53175517
``````

Level River St

@ edc65 Damnit = /我似乎想不出什么新颖的东西...我想到的几乎所有挑战都已经以某种形式完成。无论哪种方式，挑战都不是完全相同的，因为我的问题是打高尔夫球，而您不必找到平铺-只需找到它们的数量即可。也许人们可以使用漂亮的公式代替编写暴力破解程序。
orlp 2015年

edc65

orlp 2015年

3

# Pyth，30个 29字节

``````L?bsmy-tb]dfq1.a-VThbb1y*FUMQ
``````

### 说明：

``````                          UMQ  convert the input numbers into ranges
*F     Cartesian product (coords of each square)
L                              define a function y(b):
?b                              if len(b) > 0:
f         b             filter b for squares T, which satisfy:
.a-VThb                Euclidean distance between T and b[0]
q1                       is equal to 1 (direct neighbors)
m                              map each neighbor d to:
-tb]d                          remove d from b[1]
y                               and call recursively y with the rest
s                               sum all those values and return them
else:
1            return 1 (valid domino tiling found)
y*FUMQ  Call y with all coords and print the result
``````

@flawr我添加了对算法的解释。
2015年

@Jaketube感谢您的解释，我真的很喜欢递归方法！
flawr

3

# Matlab，292年

PS：如果有人知道如何使Matlab语法突出显示，请在此答案中包含相应的标签！

``````function C=f(m,n)
d = ceil(m*n/2);%number of dominoes
%enumeration: %the nth bit in the enumeration says whether the nth
% domino pice is upright or not. we enumerate like this:
% firt piece goes top left:
% next piece goes to the left most column that has an empty spot, in the
% top most empty spot of that column
C=0;%counter of all valid tilings
for e=0:2^d-1 %go throu all enumerations
%check whether each enumeration is valid
A = ones(m,n);
%empty spots are filled with 1
%filled spots are 0 (or if overlapping <0)
v=1;%flag for the validity. hte grid is assumed to be valid until proven otherwise
for i=1:d %go throu all pieces, place them in A
%find the column where to place:
c=find(sum(A)>0,1);
%find the row where to place:
r=find(A(:,c)>0,1);
%find direction of piece:
b=de2bi(e,d);
if b(i)
x=0;y=1;
else
x=1;y=0;
end
%fill in the piece:
try
A(r:r+y,c:c+x)=A(r:r+y,c:c+x)-1;
catch z
v=0;break;
end
%check whether A has no overlapping pieces
if any(A(:)<0)
v=0;break;
end
end
%if valid, count it as valid
if v && ~norm(A(:))
disp(A)
C=C+1;
end
end
``````

``````function C=f(m,n);m=4;n=6;d=ceil(m*n/2);C=0;for e=0:2^d-1;A=ones(m,n);v=1;for i=1:d;c=find(sum(A)>0,1);r=find(A(:,c)>0,1);b=de2bi(e,d);if b(i);x=0;y=1;else;x=1;y=0;end;try;A(r:r+y,c:c+x)=A(r:r+y,c:c+x)-1;catch z;v=0;break;end;if any(A(:)<0);v=0;break;end;end;if v && ~norm(A(:));C=C+1;end;end
``````

2

# C89，230字节

``````f(n,m,b)int*b;{int s,i;s=i=0;
while(b[i])if(++i==n*m)return 1;
if(i/n<m-1){b[i]=b[i+n]=1;s+=f(n,m,b);b[i]=b[i+n]=0;}
if(i%n<n-1&&!(b[i]|b[i+1])){b[i]=b[i+1]=1;s+=f(n,m,b);b[i]=b[i+1]=0;}
return s;}
g(n,m){int b[99]={};return f(n,m,b);}
``````

0

# Python 243

• 产生m * n / 2个方向；
• 尝试将多米诺骨牌固定在m * n板上。

``````import itertools as t
m,n=input()
c,u=0,m*n
for a in t.product([0,1],repeat=u/2):
l,k,r,h=[' ',]*u,0,'-|',[1,m]
for t in a:
l[k]=r[t]
k+=h[t]
if k%m<m and k/m<n and l[k]==' ':l[k]=r[t]
k=''.join(l).find(' ',1)
if k<0:c+=1
print c
``````
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.