Poj 2663 Tri Tiling dp, poj2663
Question:
For a rectangle of 3 * N (N <= 30), ask how many kinds of solutions are filled with a small rectangle of 1*2.
Analysis:
Same as poj2411.
Code:
# Include <iostream> using namespace std ;__ int64 ans [32] [4]; int n, m ;__ int64 dp [2] [1 <4]; __int64 solve () {int I, j, used; memset (dp, 0, sizeof (dp) ;__ int64 * crt = dp [0], * nxt = dp [1]; crt [0] = 1; for (I = n-1; I> = 0; -- I) for (j = s-1; j> = 0; -- j) {for (used = 0; used <(1 <m); ++ used) {if (used> j & 1) nxt [used] = crt [used &(~ (1 <j)]; else {__ int64 res = 0; if (j + 1 <m &&! (Used> (j + 1) & 1) res + = crt [used | 1 <(j + 1)]; if (I + 1 <n) res + = crt [used | (1 <j)]; nxt [used] = res ;}} swap (crt, nxt);} return crt [0];} int main () {while (scanf ("% d", & n) = 1) {if (n =-1) break; m = 3; memset (ans, -1, sizeof (ans); if (n <m) swap (n, m); if (ans [n] [m]! =-1) {printf ("% I64d \ n", ans [n] [m]); continue;} if (n * m) % 2 = 1) ans [n] [m] = 0; elseans [n] [m] = solve (); printf ("% I64d \ n ", ans [n] [m]);} return 0 ;}