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. poj 3295 Tautology 伪递归

    题目链接: http://poj.org/problem?id=3295 题目描述: 给一个字符串,字符串所表示的表达式中p, q, r, s, t表示变量,取值可以为1或0.K, A, N, C, ...

  2. Windows环境下修改Oracle实例监听IP地址

    Windows环境下修改Oracle实例监听IP地址. 配置文件路径:<ORACLE_HOME>\NETWORK\ADMIN 如:C:\Oracle11gR2\product\11.2.0 ...

  3. matlab实现算术编解码 分类: 图像处理 2014-06-01 23:01 357人阅读 评论(0) 收藏

    利用Matlab实现算术编解码过程,程序如下: clc,clear all; symbol=['abc']; pr=[0.4 0.4 0.2]; %各字符出现的概率 temp=[0.0 0.4 0.8 ...

  4. 自动化中Java面试题

    1.面向对象的特征有哪些方面?答:面向对象的特征主要有以下几个方面:- 抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象和行为抽象两方面.抽象只关注对象有哪些属性和行为,并不关注这些 ...

  5. CROSS APPLY AND CROSS APPLY

    随着业务千奇百怪,DBA数据库设计各有不同,一对多关系存JSON或字符串逗号分隔... 今天小编给大家分享一下针对这个问题的解决办法 问题一.存储过程接受参数格式为XXX,XXX 解决办法:将字符转成 ...

  6. 升级 Cocoapods 到1.2.0指定版本,降低版本及卸载

    =====================升级版本=================== CocoaPods 1.1.0+ is required to build SnapKit 3.0.0+. 在 ...

  7. IntelliJ IDEA安装与破解

    1.软件下载 文中使用到的安装包下载 2.部署 安装一路下一步即可. 把下载的JetbrainsCrack-3.1-release-enc.jar放在安装目录的bin目录下 3.修改配置文件 在安装的 ...

  8. 微信小程序组件解读和分析:十五、switch 开关选择器

    switch 开关选择器组件说明: switch,开关选择器.只能选择或者不选.这种属于表单控件或者查询条件控件. switch 开关选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯 ...

  9. VUE 入坑系列 一 基础语法

    html代码 <div id="app"> {{message}} </div> JavaScript代码 var vm = new Vue({ el: & ...

  10. .net 操作xml --移除注释节点

    /// <summary> /// xml字符串转xml文档 忽略注释信息 /// </summary> /// <param name="sXml" ...