poj2663 Tri Tiling
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj2663 Tri Tiling相关的知识,希望对你有一定的参考价值。
Tri TilingTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5843Accepted: 3128
Description
In how 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 is a line containing an integer 0 <= n <= 30.
Output
For each test case, output one integer number giving the number of possible tilings.
Sample Input
2
8
12
-1
Sample Output
3
153
2131
Source
__________________________________________________________
(参考Matrix67,图片源自Matrix67);
共8个状态,建图如上,进行n+1次矩阵乘法,然后 000—>111为答案。
__________________________________________________________
1 Program Stone; 2 3 const a:array[1..8,1..8]of longint=((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), 10 11 (0,1,0,0,0,1,0,0), 12 13 (1,0,1,0,1,0,0,0), 14 15 (0,0,0,1,0,0,0,0), 16 17 (0,0,1,0,0,0,0,0)); 18 19 type ar=array[1..8,1..8]of longint; 20 21 var i,j,k,l,n:longint; 22 23 qu,ti:ar; 24 25 26 27 Procedure time(a,b:ar); 28 29 var i,j,k:longint; 30 31 begin 32 33 fillchar(ti,sizeof(ti),0); 34 35 for i:=1 to 8 do 36 37 for j:=1 to 8 do 38 39 for k:=1 to 8 do 40 41 inc(ti[i,j],a[i,k]*b[k,j]); 42 43 end; 44 45 46 47 Procedure quick(k:longint); 48 49 begin 50 51 if k=1 then begin qu:=a;exit;end; 52 53 quick(k div 2); 54 55 time(qu,qu); 56 57 if k mod 2<>0 then time(ti,a); 58 59 qu:=ti; 60 61 end; 62 63 64 65 Begin 66 67 assign(input,‘input.in‘);reset(input); 68 69 readln(n); 70 71 while n<>-1 do 72 73 begin 74 75 quick(n+1); 76 77 writeln(qu[1,6]); 78 79 readln(n); 80 81 end; 82 83 close(input); 84 85 end.
以上是关于poj2663 Tri Tiling的主要内容,如果未能解决你的问题,请参考以下文章