poj 2506 Tiling

来源:互联网 发布:linux svn 创建仓库 编辑:程序博客网 时间:2024/06/09 20:28

一道简单的递推题 , 主要用到了大数相加。

#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <math.h>#define pr printf#define sc scanfstruct bigint{    unsigned int dig[1000];    unsigned int n;    bigint() {memset(this->dig,0,sizeof(this->dig));  n = 100;}    bigint(int n)    {        this->n = n;        memset(this->dig,0,sizeof(this->dig));    }    bigint& operator=(const bigint& a)    {        for(int i=0; i<=n; i++)           this->dig[i] = a.dig[i];        return *this;    }    friend bigint operator+(const bigint& a , const bigint& b)    {        bigint c;        int num = 0;        for(int i=0; i<=a.n; i++)        {            num = a.dig[i] + b.dig[i] + num;            c.dig[i] = num%100000;            num /= 100000;        }        return c;    }    bigint operator*(const int n)    {        int num = 0;        bigint c;        for(int i=0; i<=this->n; i++)        {            num = this->dig[i]*n + num;            c.dig[i] = num%100000;            num /= 100000;        }        return c;    }    void clear_t() {memset(this->dig,0,sizeof(this->dig)); n = 100; }    void print()    {        int i;        for(i=this->n; i>=0; i--)            if(this->dig[i]) break;        if(i >= 0)            printf("%d",this->dig[i--]);        else            printf("0");        for(; i>=0; i--)            printf("%05d",dig[i]);        printf("\n");    }};bigint arr[260];int main(){    arr[0].dig[0] = 1;    arr[1].dig[0] = 1;    arr[2].dig[0] = 3;    for(int i=3; i<=256; i++)        arr[i] = arr[i-1] + arr[i-2]*2;    int n;    while(~sc("%d",&n))    {        arr[n].print();    }}
0 0
原创粉丝点击