Long Dominoes

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on CodeForcesGym. Original ID: 100212E
64-bit integer IO format: %I64d      Java class name: (Any)

Find the number of ways to tile an m*n rectangle with long dominoes -- 3*1 rectangles.

Each domino must be completely within the rectangle, dominoes must not overlap (of course, they may touch each other), each point of the rectangle must be covered.

Input

The input contains several cases. Each case stands two integers m and n (1 <= m <= 9, 1 <= n <= 30) in a single line. The input ends up with a case of m = n = 0.

Output

Output the number of ways to tile an m*n rectangle with long dominoes.

Sample Input

3 3
3 10
0 0

Sample Output

2
28
 

Source

Author

Andrew Stankevich
 
解题:状压dp
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = <<;
LL dp[][maxn];
vector<int>g[maxn];
bool tab[][];
int stx[maxn],tot;
void dfs(int row,int st,int n) {
if(row == n) {
int tst = ;
for(int i = n-; i >= ; --i) {
tst <<= ;
tst |= tab[i][]|(tab[i][]<<);
}
g[tst].push_back(st);
stx[tot++] = tst;
stx[tot++] = st;
return;
}
if(!tab[row][]) {
if(!tab[row][] && !tab[row][]) {
tab[row][] = tab[row][] = tab[row][] = true;
dfs(row + ,st,n);
tab[row][] = tab[row][] = tab[row][] = false;
}
if(row + > n || tab[row + ][] || tab[row + ][]) return;
tab[row + ][] = tab[row + ][] = tab[row][] = true;
dfs(row + ,st,n);
tab[row + ][] = tab[row + ][] = tab[row][] = false;
} else dfs(row + ,st,n);
}
void init(int st,int n) {
memset(tab,false,sizeof tab);
for(int i = ,xst = st; i < n; ++i,xst >>= ) {
int row = xst&;
tab[i][] = row&;
tab[i][] = (row>>)&;
if(row == ) return;
}
dfs(,st,n);
}
int main() {
freopen("dominoes.in","r",stdin);
freopen("dominoes.out","w",stdout);
int m,n;
scanf("%d%d",&m,&n);
for(int i = ; i < (<<(m + m)); ++i) init(i,m);
sort(stx,stx + tot);
tot = unique(stx,stx + tot) - stx;
int cur = dp[][] = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j < tot; ++j) {
for(int k = g[stx[j]].size()-; k >= ; --k)
dp[cur][stx[j]] += dp[cur^][g[stx[j]][k]];
}
cur ^= ;
memset(dp[cur],,sizeof dp[cur]);
}
printf("%I64d\n",dp[cur^][]);
return ;
}

CodeForcesGym 100212E Long Dominoes的更多相关文章

  1. POJ1717 Dominoes[背包DP]

    Dominoes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6731   Accepted: 2234 Descript ...

  2. 2016 Multi-University Training Contest 1 I. Solid Dominoes Tilings

    Solid Dominoes Tilings Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  3. uva 11270 - Tiling Dominoes(插头dp)

    题目链接:uva 11270 - Tiling Dominoes 题目大意:用1∗2木块将给出的n∗m大小的矩阵填满的方法总数. 解题思路:插头dp的裸题,dp[i][s]表示第i块位置.而且该位置相 ...

  4. codeforces 342D Xenia and Dominoes(状压dp+容斥)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud D. Xenia and Dominoes Xenia likes puzzles ...

  5. ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】

    称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...

  6. AtCoder Beginner Contest 071 D - Coloring Dominoes

    Problem Statement We have a board with a 2×N grid. Snuke covered the board with N dominoes without o ...

  7. [LeetCode] Push Dominoes 推多米诺骨牌

    There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we si ...

  8. [Swift]LeetCode838. 推多米诺 | Push Dominoes

    There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we si ...

  9. 6993: Dominoes(纯bfs)

    题目描述Orz likes to play dominoes. Now giving an n*m chessboard and k dominoes whose size are 1*2, Orz ...

随机推荐

  1. C#控件置于底层或顶层

    btn.BringToFront();//置于顶层 btn.SendToBack();//置于底层

  2. Sort排序浅聊

    集合是什么?笔者简易描述:数组是不可变的,所以我们使用集合来代替. using.System.Collections; 非泛型集合 using.System.Collections.Gernerc;泛 ...

  3. CSS3实现边框线条动画特效

    <div class="box-line"></div> CSS代码 .box-line, .box-line::before, .box-line::af ...

  4. mysql解压缩方式安装和彻底删除

    一.安装mysql (1)将下载下来的mysql压缩文件解压缩到需要安装mysql的目录中 (2)打开解压后的文件夹,复制default.ini文件并重命名为my.ini,此文件的相关配置为: (3) ...

  5. kubernetesV1.13.1一键部署脚本(k8s自动部署脚本)

    部署k8sv1.13.1只需要下面几步就OK了: git clone https://github.com/luckman666/deploy_Kubernetes-v1.13.1.git cd de ...

  6. Android BitmapFactory.decodeFile(filePath, options) 返回 Null 6.0权限

    今天在做拍照上传的时候遇到个问题,根据路径获取Bitmap 失败,一直返回空,以为这个路径获取Bitmap代码久经考验,不怀疑它,找参数传入是否正确,初步怀疑是 filePath 没传进去,打印 fi ...

  7. javscript 导出html中的table到excel

    <script language="JavaScript" type="text/javascript"> /* * 默认转换实现函数,如果需要其他 ...

  8. IntelliJ IDEA导入JDK出现The selected directory is not a valid home for JDK问题的解决方法

    JDK版本与IDEA版本不兼容: JDK版本过高可能会造成这个问题,需与IDEA相兼容的JDK才行. 比如,用IDEA2016.3.8版本的,JDK用jdk-10.0.1_windows-x64_bi ...

  9. leetcode_654. Maximum Binary Tree

    https://leetcode.com/problems/maximum-binary-tree/ 给定数组A,假设A[i]为数组最大值,创建根节点将其值赋为A[i],然后递归地用A[0,i-1]创 ...

  10. leetcode_378. Kth Smallest Element in a Sorted Matrix_堆的应用

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...