问题
Everyday I struggle with algorithm questions and try to ask here which I can't answer. Excuse me, if I cause any headache. Anyway,
Here is the problem from the University of Waterloo ACM Programming Contest.
In how many ways can you tile a 3xn rectangle with 2x1 dominoes?
Nirvana : smells like recursion spirit
回答1:
You can solve this by using dynamic programming. Check this for a possible solution.
回答2:
Just an explicit solution to the equations given implicitly in taskinoor's answer:
Or
f[n]=((1 + (-1)^n)*((2 - Sqrt[3])^(n/2)*(-1 + Sqrt[3]) +
(1 + Sqrt[3])* (2 + Sqrt[3])^(n/2)))/(4*Sqrt[3])
if anyone cares.
Let's show 10 values (for odd n there are no solutions) {n,f[n]}:
{6, 41.},
{12, 2131.},
{18, 110771.},
{24, 5.75796*10^6},
{30, 2.99303*10^8},
{36, 1.5558*10^10},
{42, 8.08717*10^11},
{48, 4.20377*10^13},
{54, 2.18515*10^15},
{60, 1.13586*10^17}
回答3:
Just a note on how to get the explicit solution formula, the trick is to write it down recurrence as matrix multiplication, and then use the eigenvalue formula for nth power of a matrix. For the recursion above, the equation is
(not available)
You can see the four eigenvalues show up in the belisarius' explicit formula
来源:https://stackoverflow.com/questions/4803805/in-how-many-ways-can-you-tile-a-3xn-rectangle-with-2x1-dominoes