Topic Link: Click to open the link
Test instructions
The number of ways to use a 1*1*2 block to build a 2*2*n block
There are 9 states for each layer
0, all is 1.
1.
00
__
0 means this is empty, __ means the two lie flat with a block
2.
00
11
0 means that the lattice is empty, and 1 means the square is upright.
So there are 8 different states except the No. 0, then the simple transfer.
The other states are not valid and do not participate in the calculation of the answer, so there is no need to consider
#include <string> #include <iostream> #include <cstdio> #include <algorithm> #include <cmath > #include <cstring> #include <queue> #include <set> #include <map> #include <vector> Template <class t>inline BOOL Rd (T &ret) {char c; int sgn;if (C=getchar (), c==eof) return 0;while (c!= '-' && ;(c< ' 0 ' | | C> ' 9 ')) C=getchar (), sgn= (c== '-'), -1:1;ret= (c== '-')? 0: (c ' 0 '); while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 '); Ret*=sgn;return 1;} Template <class t>inline void pt (T x) {if (x <0) {Putchar ('-'); x =-X; } if (X>9) pt (X/10); Putchar (x%10+ ' 0 ');} using namespace Std;const int N = 1000100;const int mod = 1000*1000*1000+7;void Add (const int &y,int& x) {x + = Y;if (x >= MoD) X-=mod;} int D[n][9];int Main () {memset (d, 0, sizeof D);d [0][0] = 1;for (int i = 0; i < N-1; i++) {Add (d[i][1], d[i][0]); Add (d[i][ 2], d[i][0]); Add (D[i][4], d[i][0]); Add (D[i][5], d[i][0]); Add (D[i][6], d[I][0]); Add (D[i][8], d[i][0]), if (i>1) Add (D[i-2][0], d[i][0]), add (D[i][0], d[i+1][1]), add (D[i][0], d[i+1][3]); add (D[i][0], d[i+1][5]), add (D[i][0], d[i+1][7]), add (D[i][1], d[i+1][4]), add (D[i][2], d[i+1][4]); Add (D[i][3], d[i+1][2] Add (D[i][4], d[i+1][2]), add (D[i][5], d[i+1][8]), add (D[i][6], d[i+1][8]), add (D[i][7], d[i+1][6]); Add (D[i][8], d[i+ 1][6]);} int T, n;scanf ("%d", &t), while (t--) {scanf ("%d", &n);p rintf ("%d\n", D[n][0]);} return 0;}
UVA 12446 How many ... in 3d! Building Blocks DP