Tri Tiling



In how many ways can you tile a 3×n rectangle with 2×1 dominoes? Here is a sample tiling of a 3×12 rectangle.


Input
Input consists of several test cases followed by a line containing −1−1. Each test case is a line containing an integer 0≤n≤300≤n≤30.
Output
For each test case, output one integer number giving the number of possible tilings.

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n;
    int a[31];
    memset(a,1,sizeof(a));
    a[0] = 1;
    a[2] = 3;
    for(int i = 1; i<31; i += 2)
        a[i] = 0;
    for(int j = 4; j<31;j+=2)
     a[j] = a[j-2]*4-a[j-4];
    while(scanf("%d",&n)&&n!=-1)
    {
        cout<<a[n]<<endl;

    }
    return 0;
}
1 评论
  1. 嗯,逛博就可以提升自己!虽然看不懂系列。

留言