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. git介绍及安装

    git介绍 git是一个开源的分布式版本控制系统,用于敏捷高效的处理任何或大或小的项目.git是linus Torvalds为了帮助管理Linux内核开发的一个开放源码的版本控制软件. Git 与常用 ...

  2. 题解报告:hdu 4907 Task schedule

    Problem Description 有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务.有m个询问,每个询问有一个数字q,表示如果在q时间 ...

  3. 题解报告:hdu 2084 数塔(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...

  4. D. Arpa's weak amphitheater and Mehrdad's valuable Hoses 分组背包模板题

    http://codeforces.com/problemset/problem/742/D 并查集预处理出所有关系. 一开始的时候,我预处理所有关系后,然后选择全部的时候,另起了一个for,然后再判 ...

  5. Hibernate配置(通过注解配置)

    本文主要讲通过注解配置来替换Hibernate的映射文件 1.多对一配置 package com.jazz7.entity; import java.util.Date; import javax.p ...

  6. 设置webbrowser浏览器内核

    var hklm = Microsoft.Win32.Registry.LocalMachine;            var lmRun64 = hklm.OpenSubKey(@"SO ...

  7. 安装CentOS--设置网络_1

    (1)在登录黑框中输入如下命令,让CentOS 7自动获取一个IP地址: # dhclient (2)正常情况下不会有任何输出内容.用如下命令查看获取到的IP地址: # ip addr 它将返回如图所 ...

  8. Hadoop YARN学习之核心概念(2)

    Hadoop YARN学习之核心概念(2) 1. Hadoop 2.X YARN引入的新服务 1.1 新的ResourceManager纯碎作为资源调度器,是集群资源的唯一仲裁者: 1.2 用户应用程 ...

  9. 聊5块钱P2V

    上一秒还在写代码,下一秒就跑机房干活. 这台机器产制石器时代,重启一次后再就启动不了了.这个故障处理的方式我们以后再谈. 今天聊聊啥是P2V,国人总喜欢弄些稀奇古怪的定义来证明自己技术很牛X,就跟当年 ...

  10. Android基础夯实--重温动画(三)之初识Property Animation

    每个人都有一定的理想,这种理想决定着他的努力和判断的方向.就在这个意义上,我从来不把安逸和快乐看作生活目的的本身--这种伦理基础,我叫它猪栏的理想.--爱因斯坦 一.摘要 Property Anima ...