poj 2506 Tiling

来源:互联网 发布:俄罗斯 核武 知乎 编辑:程序博客网 时间:2024/06/11 13:50
Tiling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9275 Accepted: 4418

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 <string.h>#include <iostream>#include <algorithm>#include <math.h>using namespace std;int a[1002][102];int b[1002];int main(){    int n,m,i,j;    memset(a,0,sizeof(a));    a[0][0] = 1;    a[1][0] = 1;    a[2][0] = 3;    b[0] = 0;                 //长度代表的数字个数-1(数字个数是123,就是3个)    b[1] = b[2] = 0;    j = 0;    for(i = 3; i < 251; i++)    {        int temp = 0;     //是否进位        for(int e = 0; e <= j; e++)        {            a[i][e] = (a[i-1][e]+a[i-2][e]+a[i-2][e]+temp)%10;            temp = (a[i-1][e]+a[i-2][e]+a[i-2][e]+temp)/10;        }        if(temp == 0)        {            b[i] = j;        }        else        {            b[i] = ++j;            a[i][j] = temp;        }    }    while(~scanf("%d",&n))    {        for(i = b[n];i >= 0; i--)        {            printf("%d",a[n][i]);        }        printf("\n");    }}
代码菜鸟,如有错误,请多包涵!!
0 0