poj 2506

 

Tiling
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5554   Accepted: 2704

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

Source

The UofA Local 2000.10.14

分析:纯水题~~~

代码:

#include<cstdio> using namespace std; int i,j,k,n,g1,g2,a[2][17]; inline int max(int a,int b) { return a>b?a:b; } int main() { while(scanf("%d",&n)!=EOF) { for(i=2;i<17;++i)a[0][i]=a[1][i]=0; a[0][0]=a[0][1]=a[1][0]=a[1][1]=1; if(n>1) { for(g2=0,g1=i=1;i<n;g1=!g1,g2=!g2,++i) { for(k=0,j=1;j<=max(a[g1][0],a[g2][0]);++j) { a[g2][j]=2*a[g2][j]+a[g1][j]+k; k=a[g2][j]/100000; a[g2][j]%=100000; } a[g2][0]=max(a[g1][0],a[g2][0]); if(k>0)a[g2][++a[g2][0]]=k; } n=g1; } printf("%d",a[n][i=a[n][0]]); if(i>1) { for(--i;i>1;--i)printf("%5.5d",a[n][i]); printf("%5.5d/n",a[n][i]); }else printf("/n"); } return 0; } 

 

你可能感兴趣的:(poj 2506)