There is a 4xn Board, an unlimited 1X2 Domino card. Enter n to calculate the number of methods that cover the Board perfectly.
The method is as follows:
The two-dimensional array DP [N] [m] indicates the number of arrangement methods when n columns exist and the column status is M. M is represented by four bits in binary format. The a bit indicates the status of row A of the column. 1 indicates that the column is overwritten, and 0 indicates that the column is not overwritten. The initial status is:
DP [1] [3] = DP [1] [6] = DP [1] [12] = DP [1] [15] = DP [1] [0] = 1;
Status transfer:
DP [T] [15] = DP [T-1] [15] + dp [T-1] [12] + dp [T-1] [3] + dp [T-1] [6] + DP [T-1] [0];
DP [T] [9] = DP [T-1] [6];
DP [T] [12] = DP [T-1] [15] + dp [T-1] [3];
DP [T] [3] = DP [T-1] [15] + dp [T-1] [12];
DP [T] [6] = DP [T-1] [15] + dp [T-1] [9];
DP [T] [0] = DP [T-1] [15];
Code:
// Problem#: 8223// Submission#: 2127308// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <iostream>#include <algorithm>#include <cstring>using namespace std ; int main(){ int d[31][16] ; memset(d,0,sizeof(d)) ; d[1][15] = d[1][12] = d[1][6] = d[1][3] =d[1][0]= 1 ; for(int i = 2 ; i <= 30 ; i ++) { d[i][15] = d[i-1][0]+d[i-1][3]+d[i-1][6]+d[i-1][12]+d[i-1][15] ; d[i][12] = d[i-1][3] + d[i-1][15] ; d[i][9] = d[i-1][6] ; d[i][6] = d[i-1][15] + d[i-1][9] ; d[i][3] = d[i-1][15] + d[i-1][12] ; d[i][0] = d[i-1][15] ; } int k = 1 ; int n ;cin >> n ; while(n--) { int c ; cin >> c ; cout << k++ <<" " << d[c][15] << endl; }}