Tri Tiling
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2168 accepted Submission (s): 1240
Problem Description in many ways can, tile a 3xn rectangle with 2x1 dominoes? This is a sample tiling of 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
Solution: The 3*n of the floor can be 1*2 by the board seamless splicing of the number of programs, first n of the odd time is certainly unable to splice, when n is even when, the whole as f[i] by the j*3 and F[i-j] two parts, j*3 part is not by the 2*3 splicing of the scheme species number, j= At 2, there are only 3 scenarios, and there are 2 options when j!=2
#include <cstdio>
int main ()
{
int f[31];
int i,j;
int n;
F[0]=1;
for (i=1;i<=30;i+=2) f[i]=0;
for (i=2;i<=30;i+=2)
{
f[i]=0;
for (j=2;j<=i;j+=2)
{
if (j==2) f[i]+=3*f[i-j];
else f[i]+=2*f[i-j];
}
Freopen ("In.txt", "R", stdin);
Freopen ("OUT.txt", "w", stdout);
while (scanf ("%d", &n), n!=-1) printf ("%d\n", F[n]);
return 0;
}