poj2506

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define N 255
 4 int f[N][N];
 5 int main()
 6 {
 7     int i,j,n;
 8     while(~scanf("%d",&n))
 9     {
10         memset(f,0,sizeof(f));
11         f[0][0]=1;
12         f[1][0]=1;
13         f[2][0]=3;
14         if(n<=2)
15         printf("%d\n",f[n][0]);
16         else
17         {
18             int c=1;
19             for(i=3;i<=n;i++)
20             {
21                 int t=0;
22                 int s=0;
23                 for(j=0;j<c;j++)
24                 {
25                     s=2*f[i-2][j]+f[i-1][j]+t;
26                     f[i][j]=s%10;
27                     t=s/10;
28                 }
29                 if(t)
30                 {
31                     f[i][c]=t;
32                     c++;
33                 }
34             }
35             for(i=c-1;i>=0;i--)
36             printf("%d",f[n][i]);
37             printf("\n");
38         }
39     }
40     return 0;
41 }
View Code

Description

In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? 
Here is a sample tiling of a 2x17 rectangle. 

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 2xn rectangle. 

Sample Input

2
8
12
100
200

Sample Output

3
171
2731
845100400152152934331135470251
1071292029505993517027974728227441735014801995855195223534251
原文地址:https://www.cnblogs.com/sdutmyj/p/3222443.html