POJ 2506 Tiling (递推 + 大数加法模拟 )
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7965 | Accepted: 3866 |
Description
Here is a sample tiling of a 2x17 rectangle.
Input
Output
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 (递推 + 大数加法模拟 )的更多相关文章
- poj 2506 Tiling 递推
题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...
- PKU 2506 Tiling(递推+高精度||string应用)
题目大意:原题链接有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解.解题思路:1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能 ...
- POJ 2506 Tiling(递推+大整数加法)
http://poj.org/problem?id=2506 题意: 思路:递推.a[i]=a[i-1]+2*a[i-2]. 计算的时候是大整数加法.错了好久,忘记考虑1了...晕倒. #includ ...
- Tiling(递推+大数)
Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...
- 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 ...
- [ACM] POJ 2506 Tiling (递归,睑板)
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7487 Accepted: 3661 Descriptio ...
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
- ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)
Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...
- 【hdoj_1865】1sting(递推+大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...
随机推荐
- 树讲解——紧急集合(lca)
大视野 1787: [Ahoi2008]Meet 紧急集合 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3067 Solved: 1365[ ...
- Linux Perf Probes for Oracle Tracing
Luca Canali on 21 Jan 2016 Topic: this post is about Linux perf and uprobes for tracing and profilin ...
- JS中原型链中的prototype与_proto_的个人理解与详细总结(**************************************************************)
一直认为原型链太过复杂,尤其看过某图后被绕晕了一整子,今天清理硬盘空间(渣电脑),偶然又看到这图,勾起了点回忆,于是索性复习一下原型链相关的内容,表达能力欠缺逻辑混乱别见怪(为了防止新人__(此处指我 ...
- uibutton 使用settitle后如何修改其中文字对齐方式
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(5, s ...
- Window10下Apache2.4的安装和运行
以前用Python运行的Web框架都是要运行在Linux下,加上WSGI服务器,比如Gunicorn+Flask,后来了解到了Apache,看看能不能基于Apache这个Web服务器下给python提 ...
- Java并发学习 & Executor学习 & 异常逃逸 & 同步互斥Best Practice & wait/notify, conditon#await/signal
看了这篇文章:http://www.ciaoshen.com/2016/10/28/tij4-21/ 有一些Java并发的内容,另外查了一些资料. 朴素的Thread 首先,Java中关于线程Thre ...
- Docker实战(一):基础命令
# 在ubuntu中安装docker $ sudo apt-get install docker.io # 查看docker的版本信息 $ docker version # 查看安装docker的信息 ...
- 非常不错的ajax原理总结
在工作中用了Ajax N多次了,也看过一些相关方面的书籍,也算是认识了它,但是一直没有认真总结和整理过相关的东东,失败!近有闲情,将之总结如下:[名称]Ajax是Asynchronous JavaSc ...
- php.ini的载入位置
php.ini文件找不到,载入WINDOS下的,但找不到,后来强制-c查找是OK的.思考,为什么载入window下的ini文件.1.可能是有一个默认路径.2.可能没有路径.默认载入. 问题解决:htt ...
- powerDesignner连接数据库
http://hi.baidu.com/huntererpang/item/e65e1c48aa0ab50a6dc2f090 选用microsoft odbc for oracle 数据源名称:我喜欢 ...