E-tiling_easy version
The main idea: there is a grid size of 2 x N, now need to use 2 specifications of the Dominoes paved, the domino specifications are 2 x 1 and 2 x 2, please calculate how many kinds of laying method.
A simple DP question: dp[i+2]=dp[i+1]+2*dp[i]; Initial conditions: dp[1]=1;dp[2]=3;
At first did not consider clearly, the recursive relationship written dp[i+2]=3*dp[i];
Explain Dp[i+2]=dp[i+1]+2*dp[i]
DP[I+2] In contrast to dp[i] just a 2x2 square, the current i+1 lattice are filled, then the first i+2 lattice is determined, and the current I are filled, in order not to fill with the i+1 of the scheme to repeat, there are two options, directly fill 2x2 or fill two 1x2 (horizontal fill )
/** created:2016 May 12 15:24 05 sec Thu * author:akrusher**/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<string>#include<vector>#include<deque>#include<list>#include<Set>#include<map>#include<stack>#include<queue>#include<numeric>#include<iomanip>#include<bitset>#include<sstream>#include<fstream>using namespacestd;#defineRep (i,a,n) for (int i=a;i<n;i++)#definePer (i,a,n) for (int i=n-1;i>=a;i--)#defineIn (n) scanf ("%d",& (n))#defineIn2 (X1,X2) scanf ("%d%d",& (x1),& (x2))#definein3 (X1,X2,X3) scanf ("%d%d%d",& (x1),& (x2),& (x3))#defineINLL (n) scanf ("%i64d",& (n))#defineInll2 (X1,X2) scanf ("%i64d%i64d",& (x1),& (x2))#defineINLLD (n) scanf ("%lld",& (n))#defineInlld2 (X1,X2) scanf ("%lld%lld",& (x1),& (x2))#defineINF (n) scanf ("%f",& (n))#defineInf2 (X1,X2) scanf ("%f%f",& (x1),& (x2))#defineINLF (n) scanf ("%lf",& (n))#defineINLF2 (X1,X2) scanf ("%lf%lf",& (x1),& (x2))#defineInc (STR) scanf ("%c",& (str))#defineINS (str) scanf ("%s", (str))#defineOut (x) printf ("%d\n", (x))#defineOut2 (x1,x2) printf ("%d%d\n", (x1), (x2))#defineOutf (x) printf ("%f\n", (x))#defineOUTLF (x) printf ("%lf\n", (x))#defineOUTLF2 (x1,x2) printf ("%lf%lf\n", (x1), (x2));#defineOUTLL (x) printf ("%i64d\n", (x))#defineOUTLLD (x) printf ("%lld\n", (x))#defineOUTC (str) printf ("%c\n", (str))#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#defineSZ (x) ((int) (x). Size ())#defineMem (x, y) memset (x,y,sizeof (×));typedef vector<int>Vec;typedefLong LongLl;typedef pair<int,int>P;Const intdx[4]={1,0,-1,0},dy[4]={0,1,0,-1};Const intinf=0x3f3f3f3f;Constll mod=1e9+7; ll Powmod (ll A,ll b) {ll res=1; a%=mod; for(; b;b>>=1){if(b&1) Res=res*a%mod;a=a*a%mod;}returnRes;}Const BOOLAc=true; ll dp[ *];intMain () {intT,n; inch(t); dp[1]=1ll;dp[2]=3ll; Rep (I,1, to) {Dp[i+2]=2*dp[i]+dp[i+1]; } while(t--){ inch(n); OUTLLD (Dp[n]); } return 0;}
Tiling_easy version (type of lattice filled with 2 x N)