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. 用hashmap实现自己的缓存

    @SuppressWarnings({"unchecked", "rawtypes"})public class DefaultCache implements ...

  2. Engine中如何进行七参数投影转换?

    来自:http://zhihu.esrichina.com.cn/?/question/6858 解决办法]:首先创建自定义geotransformation,然后用IGeometry.Project ...

  3. 这一篇里面有很多关于scala的list的操作的好的知识

    https://www.cnblogs.com/weilunhui/p/5658860.html 1.++[B]   在A元素后面追加B元素 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  4. sql的一些知识_order by

    注释 SELECT name FROM userinfo #这是注释 /* 这是多行注释 */ order by 排序() SELECT username FROM userinfo ORDER BY ...

  5. PS 如何制作柔和的边框

    柔和边框制作 1 新建一个图层,按填充为黑色.(填充当前图层为前景色 A/T+Delete 背景色 CTRL+Delete),不透明度设为60%.混合模式为正片叠底,   2 选择椭圆选择一片区域(也 ...

  6. hibernate session缓存

    Session 概述 Session 接口是 Hibernate 向应用程序提供的操纵数据库的最基本的接口, 它提供了基本的保存, 更新, 删除和载入 Java 对象的方法. Session 具有一个 ...

  7. vue2.0 + vux (六)NewsList 资讯页 及 NewsDetail 资讯详情页

    设置代理,避免出现跨域问题 /*设置代理,避免出现跨域问题*/ proxyTable: { '/api':{ target: 'https://www.oschina.net/action/apiv2 ...

  8. 关于在 C#中无法静态库引用的解决方法

    在VS中用C#写了个类库,后面想转成静态库发现没有直接的方法,原来在C++中可以,而C#中不支持. 但是有时候程序引用C#编写的动态库觉得用户体验不好太累赘,想要简单只发一个exe可执行程序给用户就好 ...

  9. android客户端向服务器端验证登陆方法的实现2

    一.在上一篇文章中,我只是提到了其中一种方法来实现登陆 大家可以参见: http://www.apkbus.com/android-45004-1-1.html      android获取web服务 ...

  10. C# Main(string[] args)方法参数

    Main 方法是 C# 控制台应用程序或窗口应用程序的入口点,以下是各种情况下方法参数的输入方式: 1.通过vs启动,需要在“项目属性-调试-启动选项-命令行参数”中配置参数,格式为:参数一 参数二 ...