查找Domino Tiling的重复发生

时间:2015-10-19 15:15:36

标签: algorithm recursion

我正在尝试在spoj上解决this问题。使用此Link中的教程,我能够弄清楚这种情况。

*****    AA***    AA***    AA***    A****
***** =  AA***  + A****  + AA***  + A****
*****    AA***    A****    A****    AA***
*****    AA***    AA***    A****    AA***

f(n)  =  f(n-2) + h(n-1) + g(n-1) + g(n-1).

但我无法理解如何解决h(n-1)和g(n-1)的重现。

2 个答案:

答案 0 :(得分:2)

You need recurrence relations for all 16 possible profiles of the side:

##
##
##
##

#.
##
##
##

##
#.
##
##

...

##
#.
#.
#.

#.
#.
#.
#.

Here # means a cell occupied by a domino, and . an empty cell.

You can denote them by f(n,0) to f(n,15) and then the recursive relations will be rather easy to write. You can even automatically enumerate these profiles and generate the relations. Or you can manually decrease the number of profiles by a factor of 2 by noticing the symmetry (like you have noticed it for your two g's), and manually write the equations.

答案 1 :(得分:0)

您忘记了f重复出现的字词。

*****   A****    AA***    AA***    AA***    A****
*****   A****    BB***    B****    BB***    A****
*****   B****    CC***    B****    C****    BB***
*****   B****    DD***    CC***    C****    CC***
f(n)  = f(n-1) + f(n-2) + h(n-1) + g(n-1) + g(n-1)

以下是其他重现事项。我们的想法是找出最左边一列有未填充方块的所有可能的多米诺骨牌放置。

*****   A****    AA***
*****   A****    BB***
 ****    ****     ****
 ****    ****     ****
g(n)  = f(n-1) + g(n-1)

 ****    ****     ****
*****   A****    AA***
*****   A****    BB***
 ****    ****     ****
h(n)  = f(n-1) + k(n-1)

*****   AA***
 ****    ****
 ****    ****
*****   BB***
k(n)  = h(n-1)