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. 开启Windows的索引服务

    除开SearchEverything电脑内部的全硬盘搜索之外,如果要搜索文件内的内容的话,就无能为力的了.Window内置的索引服务就派上用场了,这么好的服务,默认设置居然是关闭的,想不通. 下面来介 ...

  2. 使用git的正确姿势

    1.Windows上安装git:从https://git-for-windows.github.io下载msysgit. 2.linux(Debian或Ubuntu)安装git:sudo apt-ge ...

  3. win8 报file://CBD 0xc0000034 蓝屏

    出事的机子是acer aspire v5,开机直接出直蓝屏,报file:/CBD 0xc0000034,英语的意思大约是启动文件错,可以用recovery恢复之类的 现在问题1:有好些有用的文件放在了 ...

  4. oracle数据库如何保存SQL语句?

    比如:通过系统web页面自动生成了sql语句,insert into temp(select '1,2,3',to_date(sysdate,'yyyy--mm-dd hh24:mi:ss') fro ...

  5. JS传参出现乱码(转载)

    问题说明:在进行网站开发时,将表单的提交功能交给JS来传递,但是在传递中文的过程中出现类似于繁体字的乱码. 解决方案:为了解决这个问题,首先从底层的C#代码审查,重新设置页面传值进行模拟,但是几经测试 ...

  6. 关于canvas中的jquery

    关于h5,相比前端的同事们都很了解了吧!h5里面有个canvas,现在用的蛮火.但是canvas里面的代码确实是有点繁多,特别是要对于图形做什么操作的时候...我昨天无意间发现了一个canvas的插件 ...

  7. Asp.net 引用css/js资源文件

    注意Page.ResolveUrl之前的双引号,不是单引号 <script type="text/javascript" src="<%= Page.Reso ...

  8. linux centos 安装

    本着学习的目的,在自己的电脑上进行 centos 7 安装,记录下这步骤以备忘. 一.Centos 下载 centos 官方(https://www.centos.org/)下载ISO镜像(这是我的下 ...

  9. 【Java Web】Eclipse中配置Marven环境

    1  Marven简介 Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供.基于项目对象模型(缩写:POM)概念,Maven利用一个中央信 ...

  10. 1021.Deepest Root (并查集+DFS树的深度)

    A graph which is connected and acyclic can be considered a tree. The height of the tree depends on t ...