zoukankan      html  css  js  c++  java
  • Tiling 分类: POJ 2015-06-17 15:15 8人阅读 评论(0) 收藏

    Tiling
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 8091   Accepted: 3918

    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
    这个题是一个递推,a[i]=a[i-1]+2*a[i-2],不过要注意零a[0]=1.
    
    #include <cstdio>
    #include <string.h>
    #include <cmath>
    #include <stack>
    #include <iostream>
    #include <algorithm>
    #define WW freopen("output.txt","w",stdout)
    using namespace std;
    const int Mod=10;
    const int Max=200;
    int num[300][Max];
    int main()
    {
        memset(num,0,sizeof(num));
        num[0][0]=0;
        num[1][0]=1;
        num[2][0]=3;
        for(int i=3;i<300;i++)//模拟大数
        {
            for(int j=0;j<Max;j++)
            {
                num[i][j]+=(num[i-1][j]+num[i-2][j]+num[i-2][j]);
                if(num[i][j]>=Mod)
                {
                    num[i][j+1]=num[i][j+1]+(num[i][j]/Mod);
                    num[i][j]=num[i][j]%Mod;
                }
            }
        }
        int n;
        while(~scanf("%d",&n))
        {
            if(n==0)
            {
                printf("1
    ");
                continue;
            }
            bool flag=false;
            for(int i=Max-1;i>=0;i--)
            {
                if(flag)//去前导零
                {
                    printf("%d",num[n][i]);
                }
                else
                {
                    if(num[n][i])
                    {
                        flag=true;
                        printf("%d",num[n][i]);
                    }
                }
            }
            printf("
    ");
        }
        return 0;
    }
    

     

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    第十章 嵌入式Linux的调试技术
    第九章 硬件抽象层:HAL
    第八章 让开发板发出声音:蜂鸣器驱动
    第八章GPS与Google Map定位系统
    第六章 接口驱动程序开发
    第七章 Android嵌入式组态软件
    第五章 S5PV210硬件结构
    第四章
    第三章
    第二章
  • 原文地址:https://www.cnblogs.com/juechen/p/4722023.html
Copyright © 2011-2022 走看看