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. [POI2008]海报PLA

    Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值 ...

  2. "HIBERNATE_SEQUENCE" does not exist问题处理

    JavaWeb应用在MySQL环境下可以正常运行,数据迁移至Oracle或者人大金仓后应用运行爆出如下错误: 严重: Servlet.service() for servlet [JeeCmsAdmi ...

  3. tac命令的实现 分类: linux 2014-06-02 00:08 344人阅读 评论(0) 收藏

    此程序实现简化的linux中的tac命令.即对文件按行倒序输出. 首先将文件指针置于文件尾,从后向前移动指针, 将两个换行符'\n'间的内容作为一行输出. #include<stdio.h> ...

  4. http缓存之lastModified和etag

    1.cache-control 访问资源 首次访问页面时间:2018.2.1  9:56  (当前时间=GMT时间+8h) 缓存时长max-age:1 day Expire缓存失效时间:2018.2. ...

  5. B/S和C/S示意图

    B/S C/S

  6. this关键字的构造方法的使用

    package com.wh.Object3; public class this_Demo { private String name; private double price; private ...

  7. 223 Rectangle Area 矩形面积

    在二维平面上计算出两个由直线构成的矩形叠加覆盖后的面积. 假设面积不会超出int的范围. 详见:https://leetcode.com/problems/rectangle-area/descrip ...

  8. 关于python2.7的md5加密遇到的问题(TypeError: Unicode-objects must be encoded before hashing)

    https://blog.csdn.net/u012087740/article/details/48439559 import hashlib import sys def md5s(): m=ha ...

  9. SP CAML工具

    直接一直使用CAML做一些简单的SP列表查询,突然想对CAML进一步了解,于是找到两个常用工具,做以记录: 1 Caml Query Builder : 用于编写CAML查询,对初学者可以了解查询语句 ...

  10. 5.1点击4个按钮显示相应的div

    事件:onclick 属性:display,className 用到for语句,index标记,this当前事件 先清空后附加 <!DOCTYPE html><html>< ...