Tiling

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 题目大意:给一个2*n的棋盘,用三种方块(2*2,1*2,2*1)将其铺满,为有多少种可能性。
解题思路:显然f(n)=f(n-1)+f(n-2)*2简单递推就可以。。 但是看样例就知道longlong也存不开。用string型来进行大数相加
Code:
 #include<cstdio>
#include<string>
#include<iostream>
using namespace std;
string a[];
string Add(string s1,string s2)
{
if (s1.length()<s2.length())
swap(s1,s2);
int i,j;
for(i=s1.length()-,j=s2.length()-;i>=;i--,j--)
{
s1[i]=s1[i]+(j>=?s2[j]-'':);
if(s1[i]-''>=)
{
s1[i]=(s1[i]-'')%+'';
if(i) s1[i-]++;
else s1=''+s1;
}
}
return s1;
}
int main()
{
int i,n;
a[]="",a[]="",a[]="";
for (i=; i<=; i++)
a[i]=Add(Add(a[i-],a[i-]),a[i-]);
while (cin>>n)
cout<<a[n]<<endl;
return ;
}

POJ2506——Tiling的更多相关文章

  1. poj2506 Tiling

    http://poj.org/problem?id=2506 题目大意:用多少种方法可以用2*1或2*2瓦片来铺一个2*n的矩形? 这是一个2*17长方形的样品. 输入是一行行的序列,每一行包含一个整 ...

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

    http://poj.org/problem?id=2506 #include <iostream> #include <stdio.h> #include <strin ...

  3. Texture tiling and swizzling

    Texture tiling and swizzling 原帖地址:http://fgiesen.wordpress.com If you’re working with images in your ...

  4. 图文详解Unity3D中Material的Tiling和Offset是怎么回事

    图文详解Unity3D中Material的Tiling和Offset是怎么回事 Tiling和Offset概述 Tiling表示UV坐标的缩放倍数,Offset表示UV坐标的起始位置. 这样说当然是隔 ...

  5. POJ3420Quad Tiling(矩阵快速幂)

    Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3740 Accepted: 1684 Descripti ...

  6. Tri Tiling[HDU1143]

    Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. Tiling 分类: POJ 2015-06-17 15:15 8人阅读 评论(0) 收藏

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

  8. Tiling Up Blocks_DP

    Description Michael The Kid receives an interesting game set from his grandparent as his birthday gi ...

  9. I - Tri Tiling

      Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status #in ...

随机推荐

  1. AE实现点击一个要素,并显示其属性

    第一步:根据鼠标点击处的点,找到被选中的要素 public IFeature Find2(IPoint pPoint) { ITopologicalOperator pTopoOpe = pPoint ...

  2. 关于linux下零散的东西 --慢慢补充

    一.截图     ,使用Shift+Ctrl+PrtSc就可以截图. 二.tar命令参数 c:表示压缩 x:表示解压 z:表示gzip的方式解/压缩 j:表示bzip2的方式解/压缩 三.串口终端ke ...

  3. android app widget 创建调用周期

    1 ?Android widget 大小问题 2 ?RemoteViewService Android开发历程_15(AppWidget的使用) Appwidget就是手机应用中常常放在桌面(即hom ...

  4. JS如何获取iframe内html的body值

    default页面: <html> <head> <script type="text/javascript"> window.onload=f ...

  5. [OpenXml] Read/Write row/cell from excel

    public static void test(){ using (SpreadsheetDocument document = SpreadsheetDocument.Open("test ...

  6. centos 安装ecshop出现date错误

    centos 安装ecshop 错误提示 Warning: date(): It is not safe to rely on the system's timezone settings. You ...

  7. nrm —— 快速切换 NPM 源 (附带测速功能)

    以前我们介绍过cnpmjs.org和最近推出的淘宝 npm 两个 NPM 镜像.除此之外,还有一些国外的 NPM 镜像.不同地区访问不同的镜像速度可能有差异,然后各个镜像各自都可能有少数包暂时没有同步 ...

  8. SQL Server— 存在检测、建库、 建表、约束、外键、级联删除

    /******************************************************************************** *主题: SQL Server- 存 ...

  9. Python学习_算数运算函数

    记录以grades列表为例,分别定义输出.求和.平均值.方差和标准差函数,并输出相应的值 grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90 ...

  10. MySQL Connector Net连接vs2012问题

    最近做一.NET项目,数据库用到MySQL,可是在VS2012连接数据库是遇到问题,提示:Authentication with old password no longer supported, u ...