ZOJ3209(KB3-B DLX)】的更多相关文章

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16234 题意:给p张小纸片, 问能不能选出尽量少的一部分或全部数量纸片来组成一个n*m大小的纸片, 要保证每两个纸片不能用重叠的部分 分析:把n*m的矩阵看成n*m个单位元,作为n*m列:每一个矩形分解成一行. 问题即转化为从这些行中选择最少的一部分使每一列被覆盖且仅覆盖一次. #include <cstdio> #include <cstring>…
Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, and what make it worse, he has lost some of the pieces. Luck…
精确覆盖问题:给定一个由0-1组成的矩阵,是否能找到一个行的集合,使得集合中每一列都恰好包含一个1 还有重复覆盖问题 dancing links 是 一种数据结构,用来优化搜索,不算是一种算法.(双向循环十字链表) 参阅了白书训练指南上的模版,目前只有精确覆盖,等再补上重复覆盖 struct DLX { int n , sz; // 行数,节点总数 int S[maxn]; // 各列节点总数 int row[maxnode],col[maxnode]; // 各节点行列编号 int L[max…
题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, and what make it wo…
题目:Sudoku 匪夷所思的方法,匪夷所思的速度!!! https://github.com/ttlast/ACM/blob/master/Dancing%20Link%20DLX/poj%203074.cpp #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; int flag; typedef long long LL; #define FF(i,A,s)…
很久以前就看到的一个经典题,一直没做,今天拿来练手.街霸 给n<=25个角色,每个角色有 1 or 2 个版本(可以理解为普通版以及爆发版),每个角色版本可以KO掉若干人. 问最少选多少个角色(每个角色只能选一次),使得可以KO掉其他所有人(包括所有版本). 典型的DLX.前∑mode[i]列表示被KO的人版本,重复覆盖.后n列表示选了的人,精确覆盖. 即,在精确覆盖满足的前提下,完成重复覆盖,且使所选行最少. 据说这题可以转化成只用一种覆盖,或者是dfs+剪枝.这里就先这样吧. 加了好多注释,…
题目:Sudoku 题意:求解数独.从样例和结果来看应该是简单难度的数独 思路:DFS 设置3个数组,row[i][j] 判断第i行是否放了j数字,col[i][j] 判断第i列是否放了j数字.square[i/3][j/3][x]判断第i/3行第j/3列个宫是否放置了x数字: #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <…
问题:sevenzero liked Warcraft very much, but he haven't practiced it for several years after being addicted to algorithms. Now, though he is playing with computer, he nearly losed and only his hero Pit Lord left. sevenzero is angry, he decided to cheat…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that each column, each row, and each of the nine Connecting-sub-grids that compose the grid co…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意:n个城市修建m个机场,使得每个城市到最近进场的最大值最小. 思路:二分+dlx搜索判定. #include <iostream> #include <map> #include <string> #include <stdio.h> #include <vector> #include <set> #include <a…
搜索实现:解决数独有两种思考策略,一种是枚举当前格能填的数字的种数,这里有一优化策略就是先搜索能填入种数小的格子:另一种是考虑处理某一行(列.宫)时,对于某一个没用过的数字,若该行(列.宫)只有一个可行的空白格时,就只能将该数字填入此格中.第二种实现起来略麻烦,此处仅实现第一种策略,并调整搜索顺序进行优化操作,优先搜索能填数字种数较小的格子. 另外,在搜索时,条件判断的效率尤为重要,故分别记录各行.各列.各宫已经出现的数字,这样就可以直接判断该空格填入某数字是否可行. 以POJ2676为例,无调…
下面的代码99%参考了这个网站http://www.cnblogs.com/183zyz/archive/2011/08/07/2130193.html 人生的第一道DLX肯定是需要作一些参考的啦. 题意:给你N个城市,M个雷达,你要在其中选K个,问当半径最小是多少的时候可以覆盖到所有的N个城市. 做法:二分所需要的半径r,然后处理出这时雷达能够覆盖到哪些位置.然后就转化成了一个重复覆盖问题,跑一下DLX即可. 花了两天的时间学习了一下DLX这种神奇的数据结构,它在解决精确覆盖问题上尤其有帮助,…
题意: 在N个城市选出K个城市,建飞机场(1 ≤ N ≤ 60,1 ≤ K ≤ N),N个城市给出坐标,选择这K个机场,使得从城市到距离自己最近的机场的 最大的距离 最小. 输出这个最小值. 思路: 二分+DLX,DLX判断是否合法,之前看过DLX,但是忘记了,今天看了一个博客,感觉讲解得很清晰,转载过来. DLX: 给定一个n*m的矩阵,有些位置为1,有些位置为0.如果G[i][j]==1则说明i行可以覆盖j列. 1)选定最少的行,使得每列有且仅有一个1. 2)选定最少的行,使得每列至少一个1…
思路:裸的DLX解数独.关键是建图,感觉还不如写个dfs直接,DLX写这个的代码很烦. #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<string> #include<cstdlib> #include<cstring> #include&l…
思路:裸的DLX重复覆盖 #include<set> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<string> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pb…
思路:二分枚举建边,用DLX判断是否满足. #include<set> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<string> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #…
题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 $ , $ 1 <= M <= 300$ 解法1:由于行数不多,二进制枚举选出的行数,时间复杂度为O((1<<16)*K), 其中K即为判断选出的行数是否存在相同的列中有重复的1: 优化:将1状压即可,这样300的列值,压缩在int的32位中,使得列数“好像”小于10了:这样每次只需要…
题意:有9*9的格子 每个格子 由五部分组成:上(16).右(32).下(64).左(128).和该格的数值(0~9) 若上下左右有分割格子的线 就加上相应的数, 该格的数值若为0,则是未知  1~9 则是已知 然后根据分割线 做数独(每行.每列.每宫都是1~9) 输出无解.多解或者一个解就输出那个解 这种数独与普通3*3的数独 的唯一区别就是 宫 的划分的方式不一样 16.32.64.128这几个数很特殊 分别是$2^4$.$2^5$.$2^6$.$2^7$ 也就是相应的二位数,若第4位为1,…
问题描述: 给定一个n*m的矩阵,有些位置为1,有些位置为0.如果G[i][j]==1则说明i行可以覆盖j列. Problem: 1)选定最少的行,使得每列有且仅有一个1. 2)选定最少的行,使得每列至少一个1. DLX原理: 这类属于NP问题的问题,可以使用搜索解决.但是普通的搜索必超时无疑.因此我们要设法加优化来加快速度. Dancing Links从数据结构方面对此类搜索进行了优化,通过仅保留矩阵中有用的部分提高了搜索速度.DLX的存储结构采用循环十字链表,在搜索过程中不断将不需要的部分切…
Sudoku Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3074 Appoint description:  System Crawler  (2015-04-18) Description In the game of Sudoku, you are given a large 9 × 9 grid divided into sm…
神龙的难题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 1686 Appoint description:  System Crawler  (2015-04-16) Description 这是个剑与魔法的世界.英雄和魔物同在,动荡和安定并存.但总的来说,库尔特王国是个安宁的国家,人民安居乐业,魔物也比较少.但是.总有一些魔物不时会…
Divisibility Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3335 Appoint description:  System Crawler  (2015-04-10) Description As we know,the fzu AekdyCoin is famous of math,especially in the…
对于数独问题 ; //3*3数独 ; // 一格能填9个数 9*9格 +; // 9*9*4=(9+9+9)*9+9*9 (9+9+9)是9行 9列 9格 *9是9个数 9*9是81个格子 +MaxM+; char g[MaxN]; struct DLX { int n, m, size; int U[maxnode], D[maxnode], R[maxnode], L[maxnode], Row[maxnode], Col[maxnode]; int H[MaxN], S[MaxM]; //…
Radar Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3684    Accepted Submission(s): 1398 Problem Description N cities of the Java Kingdom need to be covered by radars for being in a state of w…
直接精确覆盖 开始逐行添加超时了,换成了单点添加 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <vector> using namespace std; #define FOR(i,A,s) for(int i = A[s]; i != s; i = A[i]) #define exp 1e-8 ; int n, m, k,…
2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <vector> using namespace std; #define FOR(i,A,s) for(int i = A[s]; i != s; i = A[i]) #define exp 1e-8 , M…
Power Stations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2164    Accepted Submission(s): 626Special Judge Problem Description There are N towns in our country, and some of them are connect…
POJ 3074 : Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For example, . 2 7 3 8 . . 1 . . 1 . . . 6 7 3 5 . . . . . . . 2 9 3 . 5 6 9 2 . 8 . . . . . . . . . . . 6 . 1 7 4 5 . 3 6 4 . . . . .…
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…
题目请戳这里 题目大意:一个城市n个点,现在要建m个消防站,消防站建在给定的n个点中.求建m个消防站后,m个消防站要覆盖所有的n个点的覆盖半径最小. 题目分析:重复覆盖问题,DLX解决.不过要求覆盖半径最小,需要二分.虽然给的范围并不大,DLX毕竟还是暴力搜索,而且精度有6位小数,因此直接二分距离的话会TLE!解决方案是将图中任意2点的距离记录下来,去重后二分已知的距离.因为消防站建在给定的n个点中,那么最小覆盖半径一定在任意2点距离中产生. DLX搜索的时候,一般习惯删除的时候从左往右,不过效…