Tri Tiling Timelimit: 1000MSMemory Limit: 65536K Totalsubmissions: 5843Accepted: 3128
Description
In what many ways can you tile a 3xn rectangle with 2x1 dominoes?
Here is a sample tiling of a 3x12 rectangle.
Input
Input consists of several test cases followed by a line containing-1. Each test case was a line containing an integer 0 <= n <= 30.
Output
For each test case, the output one integer number giving the number of possible tilings.
Sample Input
2
8
12
-1
Sample Output
3
153
2131
Source
Waterloo Local 2005.09.24
__________________________________________________________
(Refer to Matrix67, image from Matrix67);
A total of 8 states, as above, the n+1 matrix multiplication, and then 000->111 as the answer.
__________________________________________________________
1 Program Stone;2 3 ConstA:Array[1..8,1..8] ofLongint= ((0,0,0,0,0,1,0,0),4 5(0,0,0,0,1,0,0,0),6 7(0,0,0,0,0,1,0,1),8 9(0,0,0,0,0,0,1,0),Ten One(0,1,0,0,0,1,0,0), A -(1,0,1,0,1,0,0,0), - the(0,0,0,1,0,0,0,0), - -(0,0,1,0,0,0,0,0)); - + typeAr=Array[1..8,1..8] ofLongint; - + varI,j,k,l,n:longint; A at Qu,ti:ar; - - - - Procedure Time (a,b:ar); - in varI,j,k:longint; - to begin + -Fillchar (Ti,sizeof (TI),0); the * fori:=1 to 8 Do $ Panax Notoginseng forj:=1 to 8 Do - the fork:=1 to 8 Do + AInc (ti[i,j],a[i,k]*b[k,j]); the + End; - $ $ - Procedure Quick (k:longint); - the begin - Wuyi ifk=1 Then beginQu:=a;exit;End; the -Quick (kDiv 2); Wu - Time (qu,qu); About $ ifKMoD 2<>0 ThenTime (ti,a); - -qu:=ti; - A End; + the - $ Begin the theAssign (input,'input.in'); reset (input); the the READLN (n); - in whilen<>-1 Do the the begin About theQuick (n+1); the theWriteln (qu[1,6]); + - READLN (n); the Bayi End; the the close (input); - - End.
poj2663 Tri Tiling