Tiling
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7509   Accepted: 3672

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

Source

 
 #include <stdio.h>
#include <string.h>
#define MAX 1000
int s[][MAX];
int main()
{
int i,j,k,t,n,len=;
memset(s,,sizeof(s));
s[][]=;
s[][]=;
s[][]=;
for(i=;i<=;i++)
{
t = ;
for(j=;j<=len;j++)
{
s[i][j]=s[i-][j]+*s[i-][j]+t;
if(s[i][j]>)
{
t=s[i][j]/;
s[i][j]%=;
}
else
t = ;
if(j==len&&t==)
len++;
}
}
while(scanf("%d",&n)!=EOF)
{
for(i=MAX-;i>&&(s[n][i]==);i--);
for(;i>=;i--)
printf("%d",s[n][i]);
printf("\n");
}
return ;
}
首先,无论任何一种方案,最左边的要么是一根竖的,要么是两根横的,要么是一个方的,对吧?所以:
当是一根竖时剩下的方案数是f[i-1]
当是两根横时剩下的方案数是f[i-2]
当是一个方时剩下的方案数是f[i-2]
故f[i]=f[i-1]+2*f[i-2]
//递推+大数 注意:0的时候输出1(暂时没搞明白为什么,请大神指教)。

poj_2506_Tiling_201407211555的更多相关文章

随机推荐

  1. PHP使用Session遇到的一个Permission denied Notice解决办法

    搜索 session.save_path 在这里你有两个选择,一个是像我一样用; 把这一行注释掉,另一个选择就是修改一个 nobody 用户可以操作的目录,也就是说有读写权限的目录,我也查了下这个默认 ...

  2. Java中static修饰符

    public class StaticTest { static int i ; static int m=30; int j ; int k=25; static{ i=10; System.out ...

  3. Scala基础篇-函数式编程的重要特性

    1.纯函数 表示函数无副作用(状态变化). 2.引用透明性 表示对相同输入,总是得到相同输出. 3.函数是一等公民 函数与变量.对象.类是同一等级.表示可以把函数当做参数传入另一个函数,或者作为函数的 ...

  4. Objective-C Memory Management 内存管理 2

    Objective-C Memory Management 内存管理  2  2.1 The Rules of Cocoa Memory Management 内存管理规则 (1)When you c ...

  5. H.264学习笔记1——相关概念

    此处记录学习AVC过程中的一些基本概念,不定时更新. frame:帧,相当于一幅图像,包含一个亮度矩阵和两个色度矩阵. field:场,一帧图像,通过隔行扫描得到奇偶两场,分别称为顶场和底场或奇场和偶 ...

  6. Sass的的使用二

    1.嵌套输出方式 nested Sass 提供了一种嵌套显示 CSS 文件的方式.例如 nav { ul { margin: 0; padding: 0; list-style: none; } li ...

  7. Windows bat 设置代理

    转自tt-0411 @echo off cls color 0A Echo The program is running... Echo Setting the ip and dns... netsh ...

  8. 【分享】4412开发板POP烧写ubuntu出错,如何挂载emmc分区解决方法

    本文转自:http://bbs.topeetboard.com 平台:4412精英版系统:ubuntu系统 按照教程烧写ubuntu文件系统,TF卡和EMMC分区都完成(总之之前的操作试了几遍都是没问 ...

  9. Android(java)学习笔记201:JNI之helloword案例(利用NDK工具)

    1. 逻辑思路过程图: 2.下面通过一个HelloWorld案例来说明一下JNI利用NDK开发过程(步骤) 分析:我们在Win7系统下编译的C语言代码,我们知道C语言依赖操作系统,不能跨平台,所以我们 ...

  10. Linux 的 Spinlock 在 MIPS 多核处理器中的设计与实现

    引言 随着科技的发展,尤其是在嵌入式领域,高性能.低功耗的处理器成为众多厂商追逐的目标,但是由于技术和工艺的瓶颈,试图在单核处理器上达到这样的目标变得越发困难,于是人们提出了多核处理器的概念.多核处理 ...