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. memcached的key,value,过期时间的限制

    1.   key值最大长度? memcached的key的最大长度是250个字符,是memcached服务端的限制. 如果您使用的客户端支持"key的前缀"或类似特性,那么key( ...

  2. UITabBarController 、TabBar背景颜色设置,UITabBarItem的文字样式(颜色和大小)UITabBarItem的位置调整

    改变UITabBarController的颜色 UIView*mView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,48)];//这是部分tabb ...

  3. Spring task定时任务

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  4. jquery实现 复选框 全选

    $("#checkAll").change(function () { $(this).closest("table") .find(":checkb ...

  5. linux命令grep及正则表达式

  6. UI第十一节——UIActivityIndicatorView

    - (void)viewDidLoad {    [super viewDidLoad];        // 创建一个UIActivityIndicatorView,大小是固定的    UIActi ...

  7. 还原MySql数据库失败:max_allowed_packet 设置过小导致记录写入失败

    MySQL根据配置文件会限制Server接受的数据包大小. 有时候大的插入和更新会受 max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES ...

  8. PHP5不重新编译,如何安装自带的未安装过的扩展,如soap扩展?

    在虚拟机的CentOS5.5中,一键安装了PHP运行环境,但发现并没有 soap 扩展,而近期项目用需要用到 webservice. 上述的一键安装(lamp0.4),其实是源码编译安装,PHP配置文 ...

  9. JavaScript学习总结(二)数组和对象部分

    pt学习总结(二)数组和对象部分 2016-09-16    分类:WEB开发.编程开发.首页精华暂无人评论     来源:trigkit4 分享到:更多1 对象部分 Object类型 Object  ...

  10. mount -t nfs 的使用

    服务安装:1. 在VMware Ubuntu中安装NFS服务: sudo apt-get install nfs-kernel-server2. 安装成功会出现配置文件/etc/exports. ls ...