poj 2506 Tiling(数学:递推+高精度)
来源:互联网 发布:ueditor internal.js 编辑:程序博客网 时间:2024/03/29 21:35
很坑的一道高精度模板题
用dp[n]保存2×n对应结果
对于2×n的矩形,分析最后两列
如果最后一列放1×2,则对应dp[n-1]种放法
如果最后两列放2×1,则对应dp[n-2]种放法
如果最后两列放2×2,则对应dp[n-2]种放法
所以dp[n] = dp[n-1]+dp[n-2]+dp[n-2]
比斐波那契增长的还快,所以要用高精度或者java大数
代码如下:
#include <cmath>#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define MAXN 250 #define esp 1e-9using namespace std;const int Base=1000000000; const int Capacity=100; typedef long long huge; struct BigInt{ int Len; int Data[Capacity]; BigInt() : Len(0) {} BigInt (const BigInt &V) : Len(V.Len) { memcpy (Data, V.Data, Len*sizeof*Data);} BigInt(int V) : Len(0) {for(;V>0;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(0); BigInt R; for(i=0;i<A.Len||i<B.Len||Carry>0;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==0 ? 0:V[V.Len-1]); for(i=V.Len-2;i>=0;i--) for(int j=Base/10;j>0;j/=10) Out<<V[i]/j%10; return Out; }BigInt dp[MAXN];int main(void) { dp[0] = dp[1] = 1.0; for(int i=2; i<=MAXN; ++i) { dp[i] = (dp[i-1]+dp[i-2]+dp[i-2]); } int n; while(scanf("%d", &n) != EOF) { cout << dp[n] << endl; } return 0;}
0 0
- poj 2506 Tiling(数学:递推+高精度)
- POJ 2506 Tiling(高精度+递推)
- POJ 2506 Tiling (递推+高精度)
- 【POJ】2506 - Tiling(递推,高精度)
- Poj 2506 Tiling (Java高精度 + 递推)
- POJ 2506 Tiling (大数+递推)
- POJ 2506 Tiling 递推
- poj - 2506 Tiling--递推
- POJ 2506 Tiling 高精度
- HDU2506 Tiling (高精度+递推)
- POJ2506 Tiling【高精度】【递推】
- poj 2506 Tiling(递推+大数加法)
- POJ-2506--Tiling (递推+大数运算)
- [ACM] POJ 2506 Tiling (递推,大数)
- poj 2506 Tiling dp 递推
- POJ 2506 Tiling ( 递推 + 大数 )
- POJ 2506 Tiling 递推+大数
- POJ 2506-Tiling(递推+大数)
- Windows 不能在 本地计算机 启动 OracleDBConsoleorcl。有关更多信息,查阅系统事件日志。如果这是非 Microsoft 服务,请与服务厂商联系,并参考特定服务错误代码 2。
- JAVA编程思想(3) - 复用类(二)
- Android经典23选择题_细节处理
- 【Leet Code】Add Two Numbers
- 将Excel数据导入mysql数据库的几种方法
- poj 2506 Tiling(数学:递推+高精度)
- Browser clientX scrollLeft clientLeft
- socket 编程2
- 最近公共祖先、区间最小值查询
- 结构之美(关于线性表所有的知识)
- COALESCE()函数
- 推荐看过的好书好教程
- 绕过WAF继续SQL注入常用方法
- Redis 学习小结