Tri Tiling[HDU1143]

Tri Tiling

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1631    Accepted Submission(s): 928

 

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
 

 

Source
University of Waterloo Local Contest 2005.09.24
 

 

Recommend
Eddy

 

#include<stdio.h>

#include<string.h>

__int64 f[35][7];

int main()

{

    memset(f,0,sizeof(f));

    f[0][0]=1;

    f[0][1]=0;

    f[0][2]=0;

    f[0][3]=1;

    f[0][4]=0;

    f[0][5]=0;

    f[0][6]=1;

    f[1][0]=0;

    int i;

    for (i=1;i<=30;i++)

    {

        if (i>=2) f[i][0]=f[i-2][0]+f[i-1][1]+f[i-1][4];

        f[i][1]=f[i-1][6];

        f[i][2]=f[i-1][5];

        f[i][3]=f[i][0]+f[i-1][4];

        f[i][4]=f[i-1][3];

        f[i][5]=f[i-1][2];

        f[i][6]=f[i][0]+f[i-1][1];

    }

    int n;

    while (scanf("%d",&n)!=EOF)

    {

        if (n==-1) return 0;

        printf("%I64d\n",f[n][0]);

    }

    return 0;

}

 

 

 

你可能感兴趣的:(HDU)