Tri Tiling
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2301 accepted Submission (s): 1314
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
When n>=4, there are two special combinations that need special consideration. F (N) ' =3*f (n-2) +2f (n-4) +2+ .... 2*f (0); So you can simplify this equation F (n-2) =3*f (n-4) +2*f (n-6) +2*f (n-8) + ... 2*f (0);
F (N)-f (n-2) =3*f (n-2)-F (n-4);
The value of such an operation must exceed the int type range so that the __int64 and long long types are the same, and the OJ system defaults to the A[0]=1;
#include <stdio.h>
#define LIM
long Long a[lim]={1,0,3,0,11};
int main ()
{
int n,i,j;
for (i=5;i<lim;i++)
{
a[i]=4*a[i-2]-a[i-4];
}
while (scanf ("%d", &n))
{
if (n==-1) break
;
printf ("%lld\n", A[n]);
return 0;
}