Solid Dominoes Tilings

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 235    Accepted Submission(s): 143

Problem Description
Dominoes are rectangular tiles with nice 2 × 1 and 1 × 2 sizes.

The tiling is called solid if it is not possible to split the tiled rectangle by a straight line, not crossing the interior of any tile. For example, on the picture below the tilings (a) and (b) are solid, while the tilings (c) and (d) are not.

Now the managers of the company wonder, how many different solid tilings exist for an m × n rectangle. Help them to find that out.

 
Input
The input file contains m and n(1≤m,n≤16).
 
Output
Output one integer number mod 1e9+7 - the number of solid tilings of m×n rectangle with 2 × 1 and 1 × 2 pavement tiles.
 
Sample Input
2 2
5 6
8 7
 
Sample Output
0
6
13514

Hint

All solid tilings for the 5×6 rectangle are provided on the picture below:

 
 
题意:
在经典的多米诺骨牌覆盖上加入限制:
覆盖后的骨牌不能被一条直线(横切、竖切)分成两部分。
求合法覆盖的方案数。
题解:
....这道题...以它的数据组数,除了在预处理出所有答案后打表,貌似没办法了.....
还有题解里面说的轮廓线dp是什么鬼?
不是状压dp一下就搞定了吗? 当然,这题比较好的一点,也是卡住我的一点就是其中的一个容斥过程。 1、首先状压dp出g[n][m]表示大小为n*m的时候,随意放置的方案数。
可以先深搜出所有的合法转移状态,存储到邻接表中。
显然合法转移数很少,那么,即使是在m=16时也只有100w种。
1<=m<=16的总转移数也只有200w种
所以这一步的总复杂度为O(n*总转移数) 2、接着,暴力来说,我们对于每个矩阵只要枚举矩阵的列的分割线,就能容斥了。
这样容斥出来的是列不能分割的情况。
行的如果在容斥一遍就不行了。
我一开始完全没有想到预处理答案打表。。。造成了思路的阻塞。。。
其实对于某种列的分割情况来说,
行的情况,是可以递推得:
令F[n]表示长为n的棋盘在枚举的宽度m且在枚举的切割方案下的行稳定方案。
那么显然
F[n] = g[n][m] - F[1]*g[n-1][m] - ..... -F[n - 1]*g[1][m]
即,利用第一条分割线做容斥。
这一步要O(n^2)
所以整个第二步打表过程要O(sigma(2^(m-1)*n*n), 1<= m <= 16)
即O(2^m * n^2) 从复杂度来说,我的方法应该是比较快的。
 const int N = , M = , MOD = 1e9 + ;
int head[ << N], son[M], nex[M], tot;
int ans[N][N], blocks[N];
int width;
int G[N][ << N], g[N][N]; inline int add(int x, int y) {
return ((x + y) % MOD + MOD) % MOD;
} inline int mul(int x, int y) {
return ((x * 1ll * y) % MOD + MOD) % MOD;
} inline void addEdge(int u, int v) {
son[tot] = v, nex[tot] = head[u];
head[u] = tot++;
} inline void searchNexState(int goalState, int nowState, int d) {
if(d == width) addEdge(goalState, nowState);
else if((goalState >> d) & ) {
if(d < width - && (goalState >> (d + ) & )) {
int nexState = nowState;
nexState |= ( << d) | ( << (d + ));
searchNexState(goalState, nexState, d + );
}
searchNexState(goalState, nowState, d + );
} else searchNexState(goalState, nowState | ( << d), d + );
} inline void getTransfer(int n) {
width = n, tot = ;
for(int i = ; i < ( << n); ++i) {
head[i] = -;
searchNexState(i, , );
}
// printf("%d\n", tot);
} inline void getG(int n, int m) {
for(int tab = head[( << m) - ]; tab != -; tab = nex[tab])
G[][son[tab]] = ;
for(int i = ; i < n; ++i) {
for(int u = ; u < ( << m); ++u) G[i + ][u] = ;
for(int u = ; u < ( << m); ++u) {
if(G[i][u]) {
for(int tab = head[u]; tab != -; tab = nex[tab])
G[i + ][son[tab]] = add(G[i + ][son[tab]], G[i][u]);
}
}
}
for(int i = ; i <= n; ++i) g[i][m] = G[i][( << m) - ];
} inline void search(int w, int now, int len) {
if(w >= width) {
blocks[len++] = now;
static int F[N], G[N];
for(int n = ; n <= ; ++n) {
int cnt = ;
for(int i = ; i < len; ++i) cnt = mul(cnt, g[n][blocks[i]]);
F[n] = G[n] = cnt;
for(int h = ; h < n; ++h)
F[n] = add(F[n], -mul(F[h], G[n - h]));
if(len & ) ans[n][width] = add(ans[n][width], F[n]);
else ans[n][width] = add(ans[n][width], -F[n]);
}
} else {
search(w + , now + , len);
blocks[len] = now;
search(w + , , len + );
}
} inline void init() {
for(int m = ; m <= ; ++m) {
width = m;
getTransfer(m);
getG(, m);
search(, , );
}
} int n, m;
int main() {
init();
while(scanf("%d%d", &n, &m) == ) printf("%d\n", ans[n][m]);
return ;
}

2016 Multi-University Training Contest 1 I. Solid Dominoes Tilings的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  3. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  4. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  5. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  6. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  7. 2016 Al-Baath University Training Camp Contest-1 G

    Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...

  8. 2016 Al-Baath University Training Camp Contest-1 F

    Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...

  9. 2016 Al-Baath University Training Camp Contest-1 D

    Description X is well known artist, no one knows the secrete behind the beautiful paintings of X exc ...

随机推荐

  1. ElasticSearch-5.0.0安装中文分词插件IK

    Install IK 源码地址:https://github.com/medcl/elasticsearch-analysis-ik,git clone下来. 1.compile mvn packag ...

  2. linux 安装 ArcSDE10.1

    实验仍未成功,步骤仅供参考. 1:首先检查一下在Linux操作系统下Oracle数据库是否能启动,是否能连通等 [oracle@localhost ~]$ sqlplus SQL*Plus: Rele ...

  3. echarts统计图使用

    网址:http://echarts.baidu.com  提示:不需要导入Jquery.js 使用: 1.导入js,echarts.js 2.创建容器 <!-- 为ECharts准备一个具备大小 ...

  4. mysql问题

    mysql x64,由于没有msi版,因此,在使用上可能会出现一些问题. 一.  配置环境变量: 只需把mysql/bin文件夹地址完整地添加到Path中,用“;”与前面的参数隔开.需注意,mysql ...

  5. 前端项目构建工具---Grunt

    什么是Grunt? grunt是javascript项目构建工具,在grunt流行之前,前端项目的构建打包大多数使用ant.(ant具体使用 可以google),但ant对于前端而言,存在不友好,执行 ...

  6. mysql [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist (转载)

    mysql报错Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist 2013-11-2 ...

  7. JavaScript对象的理解 及 字面量对象与数组的关系

    JavaScript的简单类型包括 数字.字符串.布尔值.null值.undefined值. 其他的值都是对象.对象是可变的键控集合.数组.函数.正则表达式都是对象. 对象是属性的容器,属性都是名字和 ...

  8. PHP正则表达式详解(一)

    前言: 半年前我对正则表达式产生了兴趣,在网上查找过不少资料,看过不少的教程,最后在使用一个正则表达式工具RegexBuddy时,发现他的教程写的非常好,可以说是我目前见过最好的正则表达式教程.于是一 ...

  9. C#获取命令行输出内容的方法

    获取命令行输出内容的方式有传统和异步两种方式. 传统方式: public static void RunExe(string exePath, string arguments, out string ...

  10. AC自动机

    AC自动机,全称Aho-Corasick自动机.如果没记错的话好像就是前缀自动机. 其实AC自动机就是KMP上树的产物.理解了KMP,那AC自动机应该也是很好理解的. 与KMP类似,AC自动机也是扔一 ...