Tiling
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7437   Accepted: 3635

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

特别注意输入0。输出1!。!!

。!

递推公式不难,Ai=Ai-1+2*Ai-2。非常easy就想清楚了

AC代码例如以下:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; int a[300][3005],b[3005];
int x,y,z; void work(int c)
{
int i;
memset(b,0,sizeof b);
for(i=0;i<=x;i++)
{
b[i]+=(a[c-2][i]*2);
if(b[i]>10)
{
b[i]=b[i]%10;
x++;
b[i+1]=1;
}
}
z=x+2;
for(i=0;i<=z+2;i++)
{
a[c][i]+=a[c-1][i]+b[i];
if(a[c][i]>=10&&i==z+1)
z++;
if(a[c][i]>=10)
{
a[c][i]=a[c][i]%10;
a[c][i+1]=1;
} }
x=y;y=z;
} int main()
{
int n;
int i;
while(cin>>n)
{
if(n==0)
{cout<<"1"<<endl;continue;}
int bj=0;
memset(a,0,sizeof a);
a[1][0]=1;a[2][0]=3;
x=0;y=0;
for(i=3;i<=251;i++)
work(i);
for(i=z-1;i>=0;i--)
{
if(bj==0&&a[n][i]==0)
continue;
if(a[n][i]!=0)
bj=1;
cout<<a[n][i];
}
cout<<endl;
}
return 0;
}

POJ 2506 Tiling的更多相关文章

  1. poj 2506 Tiling(递推 大数)

    题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...

  2. POJ 2506 Tiling(递推+大整数加法)

    http://poj.org/problem?id=2506 题意: 思路:递推.a[i]=a[i-1]+2*a[i-2]. 计算的时候是大整数加法.错了好久,忘记考虑1了...晕倒. #includ ...

  3. poj 2506 Tiling(java解法)

    题目链接:id=2506">http://poj.org/problem?id=2506 本题用的java解的.由于涉及到大数问题,假设对java中的大数操作不熟悉请点这儿:链接 思路 ...

  4. poj 2506 Tiling 递推

    题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...

  5. [ACM] POJ 2506 Tiling (递归,睑板)

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7487   Accepted: 3661 Descriptio ...

  6. poj 2506 Tiling(高精度)

    Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...

  7. POJ 2506 Tiling (递推 + 大数加法模拟 )

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7965   Accepted: 3866 Descriptio ...

  8. poj 2506 Tiling(大数+规律)

    poj2506Tiling 此题规律:A[0]=1;A[1]=1;A[2]=3;--A[n]=A[n-1]+2*A[n-2];用大数来写,AC代码: #include<stdio.h> # ...

  9. POJ 2506 Tiling dp+大数 水题

    大致题意:现有两种方块(1X2,2X2),方块数量无限制.问用这两种方块填满2Xn的矩阵的填法有多少种. 分析:通俗点说,找规律.专业化一点,动态规划. 状态d[i],表示宽度为i的填法个数. 状态转 ...

随机推荐

  1. 单元测试框架 unittest 的运行方法if __name__ == '__main__': unittest.main()

    1. if __name__ == '__main__': unittest.main()2. 测试用例实例根据测试的特点分组在一起. unittest为此提供了一个机制:测试套件由unittest' ...

  2. 使用js获取数组中最大、最小的数字

    1.查询最大值 var maxValue=Math.max.apply(Math,array); 2.查询最小值 var minValue=Math.min.apply(Math,array);

  3. Android AsyncTask内部线程池异步执行任务机制简要分析

    如下分析针对的API 25的AsyncTask的源码: 使用AsyncTask如果是调用execute方法则是同步执行任务,想要异步执行任务可以直接调用executeOnExecutor方法,多数情况 ...

  4. fs-max、file-nr和nofile的关系

    1. file-max /proc/sys/fs/file-max: 这个文件决定了系统级别所有进程可以打开的文件描述符的数量限制,如果内核中遇到VFS: file-max limit <num ...

  5. C# 控件的缩写

    1 btn Button 2 chk CheckBox 3 ckl CheckedListBox 4 cmb ComboBox 5 dtp DateTimePicker 6 lbl Label 7 l ...

  6. C#线程调用带参数的方法

    在 .NET Framework 2.0 版中,要实现线程调用带参数的方法有两种办法.第一种:使用ParameterizedThreadStart.调用 System.Threading.Thread ...

  7. [转载] Java并发编程:Lock

    转载自http://www.cnblogs.com/dolphin0520/p/3923167.html 以下是本文目录大纲: 一.synchronized的缺陷 二.java.util.concur ...

  8. Python中的九九乘法表(for循环)

    用for循环写出的九九乘法表(包括函数的调用) #方向一 for i in range(1,10):    for j in range(1,i+1):        d = i * j        ...

  9. web工程自动部署(tomcat服务器)

    工作中经常需要把web项目打成war包之后部署到tomcat服务器上,每次更新时步骤比较类似,这里提供公共步骤,编写名为auto_deploy.sh的shell脚本,只需要传递两个参数即可自动完成部署 ...

  10. 0e开头MD5值小结

    s878926199a 0e545993274517709034328855841020 s155964671a 0e342768416822451524974117254469 s214587387 ...