poj2663 Tri Tiling

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.