A. Tiling
Time Limit: 1000ms
Memory Limit: 32768KB
64-bit integer IO format:
%I64d Java class name:
Main
In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.
![](https://www.bnuoj.com/v3/images/fzu/1147.gif)
Input
Input is a sequence of lines, each line containing an integer number
0 <= n <= 250.
Output
For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2x
n rectangle.
Sample Input
2 8 12
Sample Output
3 171 2731
题目大意:给一个2*n的棋盘,用三种方块(2*2,1*2,2*1)将其铺满,为有多少种可能性。 结题思路:显然f(n)=f(n-1)+f(n-2)*2简单递推就可以
#include<stdio.h> #include<string.h> int a[255][150]; void fun() { a[0][0]=1; a[1][0]=1; a[2][0]=3; int flag,i,j,sum; for(i=3; i<=250; i++) { flag=0; for(j=0; j<100; j++) { sum=a[i-1][j]+(a[i-2][j])*2+flag; a[i][j]=sum%10; flag=sum/10; } } } int main() { fun(); int n; while(scanf("%d",&n)!=-1) { int i,j; for(i=100; i>=0; i--) { if(a[n][i]!=0) { for(j=i; j>=0; j--) { printf("%d",a[n][j]); } printf("\n"); break; } } } }