poj 2506

来源:互联网 发布:php 工作流 编辑:程序博客网 时间:2024/05/18 06:18
Tiling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7303 Accepted: 3555

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

2812100200

Sample Output

317127318451004001521529343311354702511071292029505993517027974728227441735014801995855195223534251//打表方法和大数相加  递推#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>int f[255][200];int main(){    int n,i,j,c,ans;    memset(f,0,sizeof(f));    f[0][0]=1;    f[1][0]=1;    f[2][0]=3;    for(i=3; i<=250; i++)    {        c=0;        for(j=0; j<200; j++)        {            ans=f[i-1][j]+2*f[i-2][j]+c;  //递推公式  f[n]=f[n-1]+2*f[n-2];            f[i][j]=ans%10000;            c=ans/10000;        }    }    while(scanf("%d",&n)!=EOF)    {        for(i=199; i>=0; i--)  //忽略前导零        {            if(f[n][i]==0)                ;            else                break;        }        printf("%d",f[n][i]);        i--;        for(; i>=0; i--)            printf("%04d",f[n][i]); //输出4位  不足4位的补零        printf("\n");    }    return 0;} 
0 0
原创粉丝点击