Medium-difficulty DP. The problem of paving bricks involves a combination of mathematical formulas. However, the search + dp method is more ...... Well, it's hard to do.
After studying the bidding process for one afternoon, I finally understood it. Compress the bricks in each layer into binary encoding, and search for whether the state conversion from the previous layer to the current layer can be achieved. Then, from 0 to 11 ...... 11dp.
Void DFS (int n, int from, int to) indicates that there are n bricks from left to right, from indicates the encoding of the First n bricks on this layer, and to indicates the next layer. After modification, 1 indicates filling, and 0 indicates vacancy. The mark was written at 01, and I spent an hour in a daze.
There is nothing else to say. For the current and next layers, there are only three possibilities for putting bricks each time: two horizontal bars, vertical bars, and vertical bars. Horizontal space means two vertical bars cannot be placed ......
# Include <cstdio>
# Include <string>
Double B [13] [1, 3000];
Int Tran [20000] [2];
Int H, W, maxmove, ntran;
Void DFS (int n, int from, int)
...{
If (n> W)
Return;
If (n = W)
...{
Tran [ntran] [0] = from;
Tran [ntran ++] [1] =;
Return;
}
DFS (n + 2, (from <2) + 3, (to <2) + 3 );
DFS (n + 1, (from <1) + 1, to <1 );
DFS (n + 1, from <1, (to <1) + 1 );
}
Void dp ()
...{
Memset (B, 0x00, sizeof (B ));
B [0] [(1 <W)-1] = 1;
Int I, J;
For (I = 0; I For (j = 0; j <ntran; j ++)
B [I + 1] [Tran [J] [1] + = B [I] [Tran [J] [0];
}
Int main ()
...{
Freopen ("in.txt", "r", stdin );
While (scanf ("% d", & H, & W ))
...{
If (! H)
Break;
Int T;
If (H <W)
...{
T = H; H = W; W = T;
}
Ntran = 0;
DFS (0, 0, 0 );
// Pt ();
DP ();
// Pb ();
Printf ("%. 0f", B [H] [(1 <W)-1]);
}
Return 0;
}