I don't quite understand the sample output.
For the case of 2xn grid, I calculated that the number of perfect matchings should be 21 (see problem 11270), and the number of hamiltonian cycles + components cycles should be 8. The total I get is 0029.
Can someone verify this?
11276 - Magical Seven
Moderator: Board moderators
Hint :-)
Hint 
When considering Hamiltonian cycles,
the complexity without precomputation becomes
~ k1*2^36*log(n/2))
Using your method, which is too slow.
However, if you do about 1 to 2 hours of precomputation
(on Pentium M 1.7ghz),
you can bring it down to
~ k2*36^3 * log(n/2)
Which runs comfortably in time
.

When considering Hamiltonian cycles,
the complexity without precomputation becomes
~ k1*2^36*log(n/2))
Using your method, which is too slow.
However, if you do about 1 to 2 hours of precomputation
(on Pentium M 1.7ghz),
you can bring it down to
~ k2*36^3 * log(n/2)
Which runs comfortably in time
