Dancing Links - nuclear weapon for Exact Cover problems

http://www.cnblogs.com/grenet/p/3145800.html
Best elaboration on dancing list I found. in Chinese.

Traditional backtracing is a heuristic-like procedure. Say, there are N items to try with one by one, when N[i] is picked, all rest N[i + 1, N-1] items would be tested one by one, too. What‘s more, due to recursive calls, there are a lot intermediate caching necessary to contain intermediate states. Very blindly procedure correct?

Traditional backtracing is like, you are trying to find a place on the ground, because you cannot see through blocks.. OK, so the computer god Donald Knuth invented a smarter tool - dancing links. This is like, find a place on a helicopter floating above the city. You are able to see all blocks, and do some bookkeeping with constant time!

Dancing Links, enables you to do a simplified, lightweighted backtracing:

- Say N[i] conflicts with N[j], N[k], etc.. j, k > i, so when N[i] is picked, N[j], N[k] are eliminated (O(1) list update ops) from candidate list automatically!

- During above procedures, you don‘t need extra buffer to store intermediate states: modified dancing links it is! So you wanna recover when backtracing? Similar const time recover do that! (O(1) list update ops)

Here is a more complex and interesting example:
http://m.blog.csdn.net/blog/mu399/7627862 (Tetris, Sudoku, N-Queens)

时间: 2024-10-06 00:43:04

Dancing Links - nuclear weapon for Exact Cover problems的相关文章

HUST 1017 - Exact cover (Dancing Links 模板题)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

HUST 1017 Exact cover (Dancing links)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 6110 次提交 3226 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

hustoj 1017 - Exact cover dancing link

1017 - Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 5851 Solved: 3092 DESCRIPTION There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in e

Dancing Link --- 模板题 HUST 1017 - Exact cover

1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 略 analyse: A Time complexity: O(n) Source code:  #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vecto

Dancing Links 专题总结

算法详细:Dancing Links博客 1.精确覆盖: ZOJ3209 Treasure Map HUST1017 Exact cover POJ3074 Sudoku 2.可重复覆盖: HDU2295 Radar FZU1686 神龙的难题

HDU 3335 Divisibility dancing links 重复覆盖

分析: dlx重复覆盖的巧用,重复覆盖的原理恰好符合本题的筛选方式,即选择一个数后,该数的倍数或约数可以保证在之后的搜索中不会被选择 于是修改一下启发函数,求解最大的重复覆盖即可. 其实不一定不被选择,只是选择以后,要么达不成目标,要不达到目标,也不如不选择更优 举下面的例子 3 2 3 6 答案一看就是 2 初始的dancing links的表示是这样的 2   3   6 2    1   0   1 3    0   1   1 6    1   1   1 然后肯定先选第一列进行删 删

bzoj1501: [NOI2005]智慧珠游戏 dancing links

精确覆盖问题,用dancing links求解. 打常量表比较麻烦. #include<bits/stdc++.h> #define FOR(i,s,t)for(node* i=(s)->t;i!=(s);i=i->t) const int f[60][12]={ {0,3,0,0,0,1,1,0}, {0,3,0,0,0,1,1,1}, {0,3,0,0,1,0,1,1}, {0,3,0,1,1,0,1,1}, {1,4,0,0,0,1,0,2,0,3}, {1,4,0,0,1,

HDU5046 Airport dancing links 重复覆盖+二分

这一道题和HDU2295是一样 是一个dancing links重复覆盖解决最小支配集的问题 在给定长度下求一个最小支配集,只要小于k就行 然后就是二分答案,每次求最小支配集 只不过HDU2295是浮点,这里是整数 我写的一个比较暴力 #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector

搜索(DLX):HOJ 1017 - Exact cover

1017 - Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 6751 Solved: 3519 Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in e