Hdu_1400
I borrowed the idea of the contour line in the DP plug. I used 1 to indicate that the corresponding position on the contour line is empty, 0 to indicate that the corresponding position has been put on something, and then DP is performed by grid.
If the top grid is 1 when the current grid is recursed, the grid and the last grid must be placed together with a vertical bone card. Otherwise, the above grid will not be filled with the bone card.
If the number of grids on the left is 0, then the number of grids on the left is 0. If the number of grids on the left is 0, the current number of grids can only be empty. If the number is 1, the current grid can be empty, or you can put a horizontal bone card with the grid on the left.
# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Define Maxd 15# Define St 4096 Typedef Long Long Ll; Int N, m; ll f [maxd] [maxd] [st]; Void Solve (){ Int I, J, K; For (I = 1 ; I <= N + 1 ; I ++ ) For (J = 1 ; J <= m; j ++ ) For (K = 0 ; K <( 1 <M + 1 ); K ++) f [I] [J] [k] = 0 ; F [ 1 ] [ 1 ] [ 0 ] = 1 ; For (I = 1 ; I <= N; I ++ ) For (J = 1 ; J <= m; j ++ ) For (K = 0 ; K <( 1 <M + 1 ); K ++ ){ If (K & 1 <J ){ If (J <m) f [I] [J + 1 ] [K ^ 1 <J] + = F [I] [J] [k]; Else F [I + 1 ] [ 1 ] [K ^ 1 <J] + = F [I] [J] [k];} Else { If (K &( 1 <J- 1 )){ If (J <m) f [I] [J + 1 ] [K ^ 1 <J- 1 ] + = F [I] [J] [k]; Else F [I + 1 ] [ 1 ] [K ^ 1 <J- 1 ] + = F [I] [J] [k];} If (J <m) f [I] [J + 1 ] [K | 1 <J] + = F [I] [J] [k]; Else F [I + 1 ] [ 1 ] [K | 1 <J] + = F [I] [J] [k] ;}} printf ( " % I64d \ n " , F [n + 1 ] [ 1 ] [ 0 ]);} Int Main (){ While (Scanf ( " % D " , & N ,& M), n ){ If (N <M) STD: swap (n, m); solve ();} Return 0 ;}