PKU 2506 Tiling(递推+高精度||string应用)
题目大意:原题链接
有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解。
解题思路:
1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能用2×1的地板
2.假设我们已经铺好了2×(n-2)的情形,则要铺到2×n则可以选择1个2×2或两个2×1,故可能有下列三种铺法

其中要注意到第三个会与铺好2×(n-1)的情况重复,故不可取,故可以得到递推式
a[n]=2*a[n-2]+a[n-1];
然后就是高精度部分,可直接用高精度的模板
解法一:递推+高精度
#include<cstring>
#include<iostream>
using namespace std; const int Base=;
const int Capacity=; struct BigInt{
int Len;
int Data[Capacity];
BigInt():Len(){}
BigInt(const BigInt &V):Len(V.Len) {memcpy(Data,V.Data,Len*sizeof*Data);}
BigInt(int V):Len() {for(;V>;V/=Base) Data[Len++]=V%Base;}
BigInt &operator=(const BigInt &V) {Len=V.Len;memcpy(Data,V.Data,Len*sizeof*Data);return *this;}
int &operator[] (int Index) {return Data[Index];}
int operator[] (int Index) const {return Data[Index];}
}; BigInt operator+(const BigInt &A,const BigInt &B){
int i,Carry();
BigInt R;
for(i=;i<A.Len||i<B.Len||Carry>;i++){
if(i<A.Len) Carry+=A[i];
if(i<B.Len) Carry+=B[i];
R[i]=Carry%Base;
Carry/=Base;
}
R.Len=i;
return R;
} ostream &operator<<(ostream &Out,const BigInt &V){
int i;
Out<<(V.Len==?:V[V.Len-]);
for(i=V.Len-;i>=;i--)
for(int j=Base/;j>;j/=)
Out<<V[i]/j%;
return Out;
} int main()
{
int n;
BigInt a[];
a[]=,a[]=;
for(int i=;i<=;i++)
a[i]=a[i-]+a[i-]+a[i-];
while(cin>>n)
cout<<a[n]<<endl;
return ;
}
解法二:递推+String应用(模拟)
#include<cstring>
#include<iostream>
using namespace std;
int n;
string a[];
string Add(string s1,string s2)
{
if(s1.length()<s2.length())
swap(s1,s2);
for(int i=s1.length()-,j=s2.length()-;i>=;i--,j--){
s1[i]=s1[i]+(j>=?s2[j]-'':);//不够则补上前导零
if(s1[i]-''>=){//判断进位
s1[i]=(s1[i]-'')%+'';//加上字符'0'将s1[i]还原为字符
if(i) s1[i-]++;
else s1=''+s1;//分情况考虑进位加一
}
}
return s1;
}
int main()
{
a[]="",a[]="";
for(int i=;i<=;i++)
a[i]=Add(Add(a[i-],a[i-]),a[i-]);
while(cin>>n)
cout<<a[n]<<endl;
return ;
}
PKU 2506 Tiling(递推+高精度||string应用)的更多相关文章
- poj 2506 Tiling 递推
题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...
- POJ 2506 Tiling (递推 + 大数加法模拟 )
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7965 Accepted: 3866 Descriptio ...
- 递推+高精度+找规律 UVA 10254 The Priest Mathematician
题目传送门 /* 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子 ...
- [luogu]P1066 2^k进制数[数学][递推][高精度]
[luogu]P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻 ...
- 递推 + 高精度 --- Tiling
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7264 Accepted: 3528 Descriptio ...
- 【BZOJ】1002: [FJOI2007]轮状病毒 递推+高精度
1002: [FJOI2007]轮状病毒 Description 给定n(N<=100),编程计算有多少个不同的n轮状病毒. Input 第一行有1个正整数n. Output 将编程计算出的不同 ...
- [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1089 分析: 第一感觉可以用一个通式求出来,但是考虑一下很麻烦,不好搞的.很容易发现最 ...
- 【BZOJ】1089: [SCOI2003]严格n元树(递推+高精度/fft)
http://www.lydsy.com/JudgeOnline/problem.php?id=1089 题意:求深度为d的n元树数目.(0<n<=32, 0<=d<=16) ...
- BZOJ 1002 FJOI2007 轮状病毒 递推+高精度
题目大意:轮状病毒基定义如图.求有多少n轮状病毒 这个递推实在是不会--所以我选择了打表找规律 首先执行下面程序 #include<cstdio> #include<cstring& ...
随机推荐
- Windows下基于eclipse的Spark应用开发环境搭建
原创文章,转载请注明: 转载自www.cnblogs.com/tovin/p/3822985.html 一.软件下载 maven下载安装 :http://10.100.209.243/share/so ...
- JavaScript第三天 boolean和json
布尔值 true:非零数字.非空字符串.非空对象 false:数字零.空字符串.null空对象.undefined json JSON(JavaScript Object Notation) 是一种 ...
- Jquery-easyUi------(布局)
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %> <! ...
- iOS各种问题处理
本文转载至:http://www.cnblogs.com/ygm900/category/436923.html 推荐初学者前去学习. mac 拷贝文件时报错 8060 解决方案 摘要: 解决 ...
- php做图片上传功能
今天来做一个图片上传功能的插件,首先做一个html文件:text.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...
- angular 2+ innerHTML属性中内联样式丢失
通过属性绑定的innerHTML,把字符串里面的html解析 解析是没问题的,但一些内联样式会丢失掉 为了不丢掉样式,需要自定义一个管道来解决这个问题 html.pipe.ts import {Pip ...
- [Jenkins] Manage Jenkins from Web Interface
URL 说明 [jenkins_url]/safeRestart This will restart Jenkins after the current builds have completed. ...
- Delphi编写下载程序:UrlDownloadToFile的进度提示
urlmon.dll中有一个用于下载的API,MSDN中的定义如下: HRESULT URLDownloadToFile( LPUNKNOWN pCaller, L ...
- Servlet------>jsp jstl核心标签库
这里不需要刻意记,在jar里,c.tld文件都有,可以自己找源码看
- Python 之RabbitMQ使用
1. IO 多路复用 # select 模拟socket server # server 端 import select import socket import sys import queue s ...