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

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

算法分析:递推公式:f[i]=f[i-1]+f[i-2]*2; 此公式也不是我自己推导出来的,我也没推导出来,我从ACM之家上的java代码看出的
公式。
代码:
#include <stdio.h>
#include <string.h>
int a[1001][501]={0};
int main()
{
int n;
int i, j, h, e;
a[0][500] = 1;
a[1][500] = 1;
a[2][500] = 3;
for(i=3; i<=250; i++)
{
h = 0;
for(j=500; j>=0; j--)
{
e=a[i-2][j]*2+a[i-1][j]+h;
a[i][j]=e%10;
h=e/10;
}
}
while(scanf("%d", &n)!=EOF)
{
if(n==0)
{
printf("1\n"); continue;
}
i = 0;
while(a[n][i]==0)
{
i++;
}
for(i; i<=500; i++)
{
printf("%d", a[n][i] );
}
printf("\n");
}
return 0;
}

这还有一份java代码,正确的!

import java.util.*;
import java.math.*;
public class Main{
static BigInteger[] ans; //
public static void main(String[] args){
Scanner reader=new Scanner(System.in);
ans = new BigInteger[251];
ans[0]=BigInteger.valueOf(1);
ans[1]=BigInteger.valueOf(1);
ans[2]=BigInteger.valueOf(3);
for(int i=3; i<=250; i++)
{
ans[i] = ans[i-1].add(ans[i-2].multiply(BigInteger.valueOf(2)));
}
int n;
while(reader.hasNextInt()){
n=reader.nextInt();
System.out.println(ans[n]);
}
}
}
												

POJ 2506 Tiling (递推 + 大数加法模拟 )的更多相关文章

  1. poj 2506 Tiling 递推

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

  2. PKU 2506 Tiling(递推+高精度||string应用)

    题目大意:原题链接有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解.解题思路:1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能 ...

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

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

  4. Tiling(递推+大数)

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

  5. Tiling 简单递推+大数

    Tiling c[0]=1,c[1]=1,c[2]=3;   c[n]=c[n-1]+c[n-2]*2;   0<=n<=250.   大数加法 java  time  :313ms 1 ...

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

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

  7. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  8. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

  9. 【hdoj_1865】1sting(递推+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...

随机推荐

  1. Codeforces 798D Mike and distribution(贪心或随机化)

    题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...

  2. 断路器Hystrix与Turbine集群监控-Spring Cloud学习第三天(非原创)

    文章大纲 一.Hystrix基础介绍二.断路器Hystrix简单使用三.自定义Hystrix请求命令四.Hystrix的服务降级与异常处理五.Hystrix的请求缓存与请求合并六.Hystrix仪表盘 ...

  3. PageHelper分页工具

    <a>共${page.total}件商品</a>    <a>共${page.pages}页</a>    <a>当前第${page.pag ...

  4. Play框架连接Mysql遇到的一些问题

    最近,在基于Play框架的项目中需要连接Mysql数据库.在这个过程中遇到了一些问题.在此,把它记录下来. 首先,Play框架和Mysql连接有两种方式,这两种方式都是在application.con ...

  5. Maven的安装文字版(Windows/Linux/Mac)

    以下内容引用自https://ayayui.gitbooks.io/tutorialspoint-maven/content/book/maven_environment_setup.html,安装信 ...

  6. AnsiString类型定义的时候可以直接指定代码页,比如950繁体字,936日文

    procedure TForm3.FormCreate(Sender: TObject); type AnsiStringForPage = type AnsiString(950);//代码页 va ...

  7. copy to tmp table

    +-----+--------+-----------+--------------+---------+------+----------------------+---------+ | Id   ...

  8. mac安装.net core

    https://www.microsoft.com/net/core#macos Install for macOS 10.11 or higher (64 bit) 1 Install pre-re ...

  9. mac git安装及github配置

    准备下载一个react的demo程序包,需要本地用到git.早就向配置了,那就安装配置一下吧. 首先,原来mac已经安装了git,版本 2.7 ,我用 brew又安装了一份git 版本 2.10.2. ...

  10. python 工具 二进制文件处理之——去掉指定长度数据包头

    包头48bit 数据98464 ...如此循环: piece_size = 48 piece_size1 = 98464 with open("C:\\Users\\Administrato ...