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. Python Day3

    一.set集合 集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 # 创建数值集合 list_1 = ...

  2. Oracle数据库开发

    Oracle数据库开发之PL/SQL基础实战视频课程 1 PL/SQL 简介 2 入门实例(一) 3 入门实例(二) 4 PL/SQL 变量和常量 5 PL/SQL数据类型(一) 6 PL/SQL数据 ...

  3. AE开发使用内存图层

    AE开发中,有时需要从磁盘中读取一些文件信息如坐标点转为图层并进行分析,此过程并不需要坐标点入库之类的操作,就可以创建一个内存图层解决问题.创建内存图层需要用到InMemoryWorkspaceFac ...

  4. getResourceAsStream和getResource的用法及Demo实例

    用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大家最经常用的,就是用JAVA的File类,如要取得 D:/test.txt文件,就会这样用File file ...

  5. 跟随 Web 标准探究DOM -- Node 与 Element 的遍历

    写在前面 这篇没有什么 WebKit 代码的分析,因为……没啥好分析的,在实现里无非就是树的(先序DFS)遍历而已,囧哈哈哈……在WebCore/dom/Node.h , WebCore/dom/Co ...

  6. Excel 锁定特定单元格 不允许更改

    1.首先,excel默认所有单元格都是被"锁定"的--当"锁定单元格"按钮被激活时. 因此,第一步,选择所有单元格,设置单元格格式,取消"保护&quo ...

  7. R语言学习笔记-机器学习1-3章

    在折腾完爬虫还有一些感兴趣的内容后,我最近在看用R语言进行简单机器学习的知识,主要参考了<机器学习-实用案例解析>这本书. 这本书是目前市面少有的,纯粹以R语言为基础讲解的机器学习知识,书 ...

  8. android学习链接

    Android studio/Gradle学习资源:http://www.cnblogs.com/licheetec/p/4475426.html

  9. 明晨HOSTS编辑器mcHostsEdtor与火狐HostAdmin配合使用

    在开发过程中,需要经常切换环境开发.测试.Stage和正式环境,甚为麻烦. 后来找到了HOST切换工具mcHostsEdtor工具快速切换host,但浏览器比如有HOST缓存,后来同事推荐FireFo ...

  10. SET基本数据类型

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAADZCAIAAACo85tgAAAgAElEQVR4Aey9SdAs13XnV/P8jW8e8D