hdoj 1143 Tri Tiling 【递推】

Tri Tiling

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


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
 



/*题意:
用2*1的小矩形有几种方法摆出3*n的大矩形.
a[0] = 1,a[1]=0,a[2]=3,a[3]=0,只要n是奇数a[n]=0
递推 a[n] = 4*a[n-2]-a[n-4];
*/
#include<stdio.h>
#include<string.h>
int a[33];
int main()
{
	int i,j,n;
	a[0] = 1;
	a[1] = 0;
	a[2] = 3;
	a[3] = 0;
	for(i = 4; i < 33;i++)
		a[i] = 4*a[i-2] - a[i-4];
	while( scanf("%d",&n),n!=-1)
	printf("%d\n",a[n]);
	return 0;
}


你可能感兴趣的:(hdoj 1143 Tri Tiling 【递推】)