Tri Tiling Problem

 

Problem 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
T(2)=3 ; 
T(0)=1;
T(2*k-1)=0
T(2*k)=3*T(2*k-2)+2*(T(2*k-4)+T(2*k-6)+..+T(2) )
#include <stdio.h>
long T[31];
long t(int n)
{
    int i;
    if(n==2)return 3;
    if(T[n]!=0)return T[n];
    else 
    {
        T[n]=3*t(n-2)+2;
        for(i=n-4;i>=2;i=i-2)
         T[n]+=2*t(i);
    }
    


    return T[n];
}
void main()
{
    int input;
    scanf("%d",&input);
    while(input!=-1){
        if(input%2==1)printf("0/n");
        else if(input==0)printf("1/n");
        else printf("%ld/n",t(input));
        scanf("%d",&input);
    }
} 

你可能感兴趣的:(Tri Tiling Problem)