CodeForcesGym 100212E Long Dominoes
Long Dominoes
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
#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的更多相关文章
- POJ1717 Dominoes[背包DP]
Dominoes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6731 Accepted: 2234 Descript ...
- 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 ...
- uva 11270 - Tiling Dominoes(插头dp)
题目链接:uva 11270 - Tiling Dominoes 题目大意:用1∗2木块将给出的n∗m大小的矩阵填满的方法总数. 解题思路:插头dp的裸题,dp[i][s]表示第i块位置.而且该位置相 ...
- codeforces 342D Xenia and Dominoes(状压dp+容斥)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud D. Xenia and Dominoes Xenia likes puzzles ...
- ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】
称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...
- 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 ...
- [LeetCode] Push Dominoes 推多米诺骨牌
There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we si ...
- [Swift]LeetCode838. 推多米诺 | Push Dominoes
There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we si ...
- 6993: Dominoes(纯bfs)
题目描述Orz likes to play dominoes. Now giving an n*m chessboard and k dominoes whose size are 1*2, Orz ...
随机推荐
- 2018年全国多校算法寒假训练营练习比赛(第五场):A题:逆序数(树状数组or归并排序)
题目描述 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.比如一个序列为4 5 1 3 2, 那么这个序列 ...
- Android内存堆上限Android的缺省值是16M(某些机型是24M)
转自: http://www.cnblogs.com/jacktu/archive/2010/12/30/1921475.html 大家都知道Android的上层应用是基于 Dalvik Virtua ...
- 在面试官问你BS和CS区别的时候如何回答??
这是我下来整理好的,如果哪里不全,望大家多多指教 C/S是Client/Server的缩写.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.Inform ...
- asp.net网站接入QQ登录
这两天在做网站第三方登录,总结一下QQ登录吧,支付宝就不用了(下载dome把ID什么的换一换就基本可以了.),本文主要说的是代码的实现方式,逻辑部分主要还是根据帮助文档来的.不懂的同学可以先看看文档. ...
- AJPFX对equals()方法和==异同的比较
equals()方法是Object类的方法,所有的类都集成了此方法,还有部分类重写了这个方法,我们看一下Object类中关于该方法的的源码: public boolean equals(Object ...
- CF949B A Leapfrog in the Array
思路: 最终的时候,对于位置p,若p是奇数,则该位置的元素是(p + 1) / 2:若p是偶数,需要从p开始不断地迭代寻找上一次跳跃所处的位置(p = p + n - p / 2),直到p是奇数为止. ...
- mac系统 usr/ 目录下无法新建文件夹???
这个问题是在操作mongodb的时候遇到的,很苦恼.目前已经解决,将解决方法分享给各位遇到同样问题的你们. 1.重启电脑,开始关机就立马按住command+R,进入macOS恢复功能界面,进入的时间可 ...
- t-sql的楼梯:超越基本级别6:使用案例表达式和IIF函数
t-sql的楼梯:超越基本级别6:使用案例表达式和IIF函数 源自:Stairway to T-SQL: Beyond The Basics Level 6: Using the CASE Expre ...
- template or render function not defined.
template or render function not defined. H_婷 关注 2018.08.16 17:22 字数 106 阅读 3859评论 0喜欢 2 下午写 Vue $par ...
- Luogu P4299 首都 LCT
既然是中文题目,这里便不给题意. 分析: 这个题的做法据说是启发式合并? 但是我不会啊…… 进入正题,LCT是怎样做掉这道题的.记得在前面的一篇<大融合>的题解中,介绍过LCT维护子树信息 ...