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. APP的消息推送(极光推送)

    APP的消息推送,使用的第三方平台是极光推送 简单案例(以Thinkphp为例): 1.下载下载PHPSDK 2.把PHPSDK目录下的jpush-api-php-client-3.5.1\src\J ...

  2. MEF 根据配置注入Service

    有这样的场景 : 现在一个接口有很多种实现类,需要根据配置,来确定确定调用哪个具体的实现类.这样使得软件扩展性大大提高 在MEF可以通过ExportMetadata 来实现这样的效果. 1.现在我们建 ...

  3. @Controller和@RestController的区别?

    @Controller和@RestController的区别?官方文档:@RestController is a stereotype annotation that combines @Respon ...

  4. LYDSY模拟赛day1 Walk

    /* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...

  5. [Python] Python学习笔记之常用模块总结[持续更新...]

    作为一种极其简单的编程语言,Python目前成为了最炙手可热的几种语言之一.它不仅简单易学,而且它还为用户提供了各种各样的模块,功能强大,无所不能.有利必有弊,学习Python同样有困扰,其中之一就是 ...

  6. PHP求余函数fmod()

    定义和用法 fmod() 函数返回除法的浮点数余数. 语法 fmod(x,y) 参数 描述 x 必需.一个数. y 必需.一个数. 说明 返回被除数(x)除以除数(y)所得的浮点数余数.余数(r)的定 ...

  7. python %s深入解析

    默认我们通常用字符串填充它 'Keep %s, and you will aways make %' % ('moving', 'it') 如果你就此止步,那就错过了一些神乎其技的用法 比如: arr ...

  8. java27

    1:反射(理解)    (1)类的加载及类加载器    (2)反射:        通过字节码文件对象,去使用成员变量,构造方法,成员方法    (3)反射的使用        A:通过反射获取构造方 ...

  9. C#反射机制 Type类型

    using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System ...

  10. 【转】如何使用VS 2013发布一个可以在Windows XP中独立运行的可执行文件

    问题描述: 用VS2013写好一个程序,在本机上运行一切正常.但是如果直接把exe文件放到另一台机器上用,则会出现: Windows XP:不是一个正常的win32程序 Window 7:缺少msvc ...