POJ 2506 Tiling (recursive + high precision)

Source: Internet
Author: User

" Topic link " click here~~

"The main topic "

In what many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.

" problem-solving ideas ":

(1) A 2*2 lattice has three methods of filling:

Two of them sideways,

Two of them stood upright,

Put a 2*2.

(2) A recursive formula is obtained f[i]=f[i-1]+f[i-2]*2

And then it's a high-precision template.

Code

/*AUTHOR:HRW recursion + High precision! * * #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using     namespace Std;const int Base=1e9;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];};     int compare (const BigInt &a, const BigInt &b) {if (A.len!=b.len) return a.len>b.len? 1:-1;     int i;     For (i=a.len-1;i>=0 && a[i]==b[i];i--);     if (i<0) return 0; Return a[i]>b[i]? 1:-1;}     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;}     BigInt operator-(const BigInt &a,const BigInt &b) {int I,carry (0);     BigInt R;     R.len=a.len;         for (i=0;i<r.len;i++) {r[i]=a[i]-carry;         if (I<b.len) r[i]-=b[i];         if (r[i]<0) carry=1,r[i]+=base;     else carry=0;     } while (r.len>0&&r[r.len-1]==0) r.len--; return R;}     BigInt operator* (const BigInt &a,const int &b) {int i;     Huge Carry (0);     BigInt R; for (i=0;i<a.len| |         carry>0;i++) {if (I<a.len) Carry+=huge (a[i]) *b;         R[i]=carry%base;     Carry/=base;     } r.len=i; return R;}     IStream &operator>> (IStream &in,bigint &v) {char Ch;         for (v=0;in>>ch;) {v=v*10+ (ch-' 0 ');     if (In.peek () <= ") break; } return in;} 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 Fa[10000];int Main () {fa[0]=fa[1]=1,fa[2]=3;    for (int i=3;i<=250;i++) {fa[i]=fa[i-1]+fa[i-2]+fa[i-2];    } unsigned long long n;    while (cin>>n) {cout<<fa[n]<<endl; } return 0;}


POJ 2506 Tiling (recursive + high precision)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.