Long dominoestime limit:1000msmemory limit:65536kbthis problem'll be judged onCodeforcesgym. Original id:100212e
64-bit integer IO format: %i64d Java class name: (any)
Find the number of ways to tile a m*n rectangle with long dominoes--3*1 rectangles.
Each domino must is completely within the rectangle, dominoes must not overlap (of course, they), EAC H point of the rectangle must is covered.
Input
The input contains several cases. Each case stands the integers m and n (1 <= m <= 9, 1 <= n <=) in a single line. The input ends up and a case of M = n = 0.
Output
Output the number of ways to tile a m*n rectangle with long dominoes.
Sample Input
3 33 100 0
Sample Output
228
SourceAndrew Stankevich ' s Contest #4
AuthorAndrew Stankevich Problem Solving: pressure DP
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intMAXN =1<< -;5LL dp[2][MAXN];6vector<int>G[MAXN];7 BOOLtab[Ten][Ten];8 intStx[maxn],tot;9 voidDfsintRowintStintN) {Ten if(Row = =N) { One intTST =0; A for(inti = n1; I >=0; --i) { -TST <<=2; -TST |= tab[i][1]| (tab[i][2]<<1); the } - G[tst].push_back (ST); -stx[tot++] =TST; -stx[tot++] =St; + return; - } + if(!tab[row][0]) { A if(!tab[row][1] &&!tab[row][2]) { attab[row][0] = tab[row][1] = tab[row][2] =true; -DFS (row +1, st,n); -tab[row][0] = tab[row][1] = tab[row][2] =false; - } - if(Row +3> N | | Tab[row +1][0] || Tab[row +2][0])return; -Tab[row +2][0] = Tab[row +1][0] = tab[row][0] =true; inDFS (row +3, st,n); -Tab[row +2][0] = Tab[row +1][0] = tab[row][0] =false; to}ElseDFS (row +1, st,n); + } - voidInitintStintN) { thememset (tab,false,sizeoftab); * for(inti =0, xst = st; I < n; ++i,xst >>=2) { $ introw = xst&3;Panax Notoginsengtab[i][0] = row&1; -tab[i][1] = (row>>1) &1; the if(Row = =2)return; + } ADfs0, st,n); the } + intMain () { -Freopen ("dominoes.in","R", stdin); $Freopen ("Dominoes.out","W", stdout); $ intM,n; -scanf"%d%d",&m,&n); - for(inti =0; I < (1<< (M + m)); ++i) init (i,m); theSort (Stx,stx +tot); -tot = unique (stx,stx + tot)-STX;Wuyi intCur = dp[0][0] =1; the for(inti =1; I <= N; ++i) { - for(intj =0; J < tot; ++j) { Wu for(intK = G[stx[j]].size ()-1; K >=0; --k) -DP[CUR][STX[J]] + = dp[cur^1][g[stx[j]][k]]; About } $Cur ^=1; -memset (Dp[cur],0,sizeofdp[cur]); - } -printf"%i64d\n", dp[cur^1][0]); A return 0; +}
View Code
Codeforcesgym 100212E Long Dominoes