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. 关键字 const

    如果关键字出现在星号左边,表示被指物是常量: 如果出现在星号右边,表示指针本身是常量: 如果出现在星号两边,表示被指物和指针都是常量. void f1(const Widget* pw); //f1和 ...

  2. Source Insight 技巧总结

    以下文章转载自网络:http://blog.csdn.net/junjie319/article/details/6910992 http://www.cnblogs.com/bluestorm/ar ...

  3. Ueditor设置默认字体

    其实很简单,只需要将ueditor.all.js 以及 ueditor.all.min.js 两个文件中的字体改掉即可 修改方法: 在ueditor.all.js中搜索:设置默认字体和字号: 在ued ...

  4. C插入排序

    #include "stdio.h" int main() { ,,,,,}; int i,j; ;j<]);j++) { int key = a[j]; ;i>=&a ...

  5. Cookie和Seesion的区别

    一.Cookie对象: 1.Cookie是由网络服务器发送出来,存在在浏览器上,它是个存储在浏览器目录中的文本文件.当浏览该cookie对应的站点时,cookie作为http头部文件的一部分在浏览器和 ...

  6. JavaScript 风格指导(Airbnb版)

    JavaScript 风格指导(Airbnb版) 用更合理的方式写 JavaScript 原文 翻译自 Airbnb JavaScript Style Guide . 目录 类型 引用 对象 数组 解 ...

  7. 《Java并发编程实战》读书笔记(更新中)

    一.简介 1.多线程编程要注意的几点: 安全性:永远不发生糟糕的事情 活跃性:某件正确的事情最终会发生(不会发生无限循环或者死锁) 性能:正确的事尽快发生(上下文切换消耗之类的) 二.线程安全 1.为 ...

  8. HTMLEncode httpencode UTF8Encode

    1.引用单元:  httpApp; 2. 对于 http Post的提交内容,应该是:   HttpEncode(Utf8Encode(StrValue));   不然与web方式的 Url_enco ...

  9. 一个例子说明如何在DataSnap中使用FireDAC

    一.FireDAC调用DataSnap远程方法查询数据示例 1.服务端使用FDQUERY查询数据并返回TDATASET: function TServerMethods1.GetData(var sq ...

  10. Speech Patterns (string)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...