首页 > 代码库 > POJ2506:Tiling(递推+大数斐波那契)

POJ2506:Tiling(递推+大数斐波那契)

http://poj.org/problem?id=2506

#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int a[260][260];int main(){    int n,i,j;    memset(a,0,sizeof(a));    a[0][0]=1;    a[1][0]=1;    a[2][0]=3;    for (i=3; i<=250; i++)    {        for (j=0; j<=250; j++)        {            a[i][j]=a[i][j]+a[i-2][j]*2+a[i-1][j];            if (a[i][j]>9)            {                a[i][j+1]=a[i][j]/10;                a[i][j]=a[i][j]%10;            }        }    }    while(scanf("%d",&n)!=EOF)    {        int flag=0;        for(i=250; i>=0; i--)        {            if(flag||a[n][i])            {                flag=1;                printf("%d",a[n][i]);            }        }        printf("\n");    }    return 0;}

 

POJ2506:Tiling(递推+大数斐波那契)