Description:
How many methods are there to build a 4 x W rectangle with a domino card of 1X2?
Analysis:
Classic question. It seems that I have done many series of such questions, and I finally got started ~
- /*
- Zju2994 tiling a grid with dominoes
- */
- # Include <stdio. h>
- # Include <string. h>
- # Define n 100
- # Define l 20
- # Define CLR (a) memset (A, 0, sizeof ())
- Int MX [l] [l];
- Void print (int A [], int N ){
- Int I;
- For (I = 0; I <n; I ++) printf ("% d", a [I]);
- Puts ("");
- }
- Int a2i (int A []) {
- Int I, x = 0;
- For (I = 0; I <4; I ++)
- X | = A [I] <I;
- Return X;
- }
- Void i2a (int x, int A []) {
- Int I;
- For (I = 0; I <4; I ++)
- A [I] = (x> I) & 1;
- }
- Void fillb (int I, int A [], int K, int B []) {
- Int J, R;
- If (k> = 4 ){
- J = a2i (B );
- MX [I] [J] = 1;
- Return;
- }
- If (A [k] = 1 ){
- B [k] = 0;
- Fillb (I, A, K + 1, B );
- }
- Else {
- If (k <3 & A [k + 1] = 0 ){
- B [k] = B [k + 1] = 0;
- Fillb (I, A, K + 2, B );
- }
- B [k] = 1;
- Fillb (I, A, K + 1, B );
- }
- }
- Void matrix (void ){
- Int I, J, K;
- Int A [L], B [l];
- For (I = 0; I <16; I ++ ){
- I2a (I, );
- Fillb (I, A, 0, B );
- }
- }
- Int main ()
- {
- Int I, J, K;
- CLR (MX );
- Matrix ();
- // DP
- Int f [N] [l];
- Int n = 30;
- CLR (f );
- F [0] [0] = 1;
- For (I = 1; I <= N; I ++ ){
- For (j = 0; j <L-1; j ++ ){
- F [I] [J] = 0;
- For (k = 0; k <L-1; k ++ ){
- If (MX [k] [J])
- F [I] [J] + = f [I-1] [k];
- }
- }
- }
- Int T, TN;
- Scanf ("% d", & Tn );
- For (t = 1; t <= tn; t ++ ){
- Scanf ("% d", & I );
- Printf ("% d/N", T, F [I] [0]);
- }
- Return 0;
- }