题目链接

精确覆盖的模板题, 把每一个格子当成一列就可以。

S忘记初始化TLE N次, 哭晕在厕所......

 #include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = ;
const int maxNode = ;
struct DLX {
int L[maxNode], R[maxNode], U[maxNode], D[maxNode], row[maxNode], col[maxNode];
int S[maxn], H[maxn], deep, sz, n, m, num;
void remove(int c) {
L[R[c]] = L[c];
R[L[c]] = R[c];
for(int i = D[c]; i!=c; i = D[i])
for(int j = R[i]; j!=i; j = R[j]) {
U[D[j]] = U[j];
D[U[j]] = D[j];
S[col[j]]--;
}
}
void resume(int c) {
for(int i = U[c]; i!=c; i = U[i])
for(int j = L[i]; j!=i; j = L[j]) {
S[col[j]]++;
D[U[j]] = j;
U[D[j]] = j;
}
R[L[c]] = c;
L[R[c]] = c;
}
void dfs(int d) {
if(d>=deep)
return ;
if(R[] == ) {
deep = min(d, deep);
return ;
}
int c = R[];
for(int i = R[]; i!=; i = R[i])
if(S[c]>S[i])
c = i;
remove(c);
for(int i = D[c]; i!=c; i = D[i]) {
for(int j = R[i]; j!=i; j = R[j])
remove(col[j]);
dfs(d+);
for(int j = L[i]; j!=i; j = L[j])
resume(col[j]);
}
resume(c);
return ;
}
void add(int r, int c) {
sz++;
col[sz] = c;
S[c]++;
U[sz] = U[c];
D[sz] = c;
D[U[c]] = sz;
U[c] = sz;
if(~H[r]) {
R[sz] = H[r];
L[sz] = L[H[r]];
L[R[sz]] = sz;
R[L[sz]] = sz;
} else {
H[r] = L[sz] = R[sz] = sz;
}
}
void init(){
mem1(H);
for(int i = ; i<=n; i++) {
R[i] = i+;
L[i] = i-;
D[i] = U[i] = i;
}
R[n] = ;
L[] = n;
mem(S);
sz = n;
deep = inf;
}
void solve() {
scanf("%d%d%d", &n, &m, &num);
n *= m;
init();
int x1, y1, x2, y2;
int cnt = ;
while(num--) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
for(int i = x1+; i<=x2; i++) {
for(int j = y1+; j<=y2; j++) {
add(cnt, (i-)*m+j);
}
}
cnt++;
}
dfs();
if(deep == inf) {
puts("-1");
} else {
printf("%d\n", deep);
}
}
}dlx;
int main()
{
int t;
cin>>t;
while(t--) {
dlx.solve();
}
}

ZOJ 3209 Treasure Map 精确覆盖的更多相关文章

  1. ZOJ 3209 Treasure Map(精确覆盖)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  2. (简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。

    Description Your boss once had got many copies of a treasure map. Unfortunately, all the copies are ...

  3. zoj 3209.Treasure Map(DLX精确覆盖)

    直接精确覆盖 开始逐行添加超时了,换成了单点添加 #include <iostream> #include <cstring> #include <cstdio> ...

  4. zoj - 3209 - Treasure Map(精确覆盖DLX)

    题意:一个 n x m 的矩形(1 <= n, m <= 30),现给出这个矩形中 p 个(1 <= p <= 500)子矩形的左下角与右下角坐标,问最少用多少个子矩形能够恰好 ...

  5. ZOJ 3209 Treasure Map (Dancing Links 精确覆盖 )

    题意 :  给你一个大小为 n * m 的矩形 , 坐标是( 0 , 0 ) ~ ( n , m )  .然后给你 p 个小矩形 . 坐标是( x1 , y1 ) ~ ( x2 , y2 ) , 你选 ...

  6. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  7. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  8. ZOJ 3209 Treasure Map DLX

    用最少的矩阵覆盖n*m的地图.注意矩阵不能互相覆盖. 这里显然是一个精确覆盖,但因为矩阵拼接过程中,有公共的边,这里须要的技巧就是把矩阵的左边和以下截去一个单位. #include <stdio ...

  9. ZOJ3209 Treasure Map —— Danc Links 精确覆盖

    题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 ...

随机推荐

  1. html系列教程--center dl dt dd div

    <center> 标签:对其所包括的文本进行水平居中. <datalist> 标签:定义列表,与 input 元素配合使用该元素,来定义 input 可能的值 demo: &l ...

  2. 20141129 LinQ to SQL

    ORMO-Object对象R-Relation关系M-Mapping映射 对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是 ...

  3. HighlightingSystem插件使用(边缘发光)

    插件链接: http://pan.baidu.com/s/1dFwkaTr 密码: nw2c 导入Unity里面可能会报错,不过没关系,直接注释掉就可以了,我用的是Unity5.1的版本 可以看到如下 ...

  4. MySQL:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

    MySQL在删除一张表时出现 ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fa ...

  5. java获得平台相关的行分隔符和java路径分隔符的方法

    System.getProperties(): 行分隔符在windows 下是 \r\n,在Linux下面是 \n, 在Mac下是 \r路径分隔符在windows下是 \ ,在LInux下是 / Sy ...

  6. Cmd批处理语法实例

    @echo on :循环获取指定目录下以php为后缀的文件,且重命名后缀为html :for /r "E:\aaa\web" %%v in (*.php) do ren " ...

  7. python退格、方向键无法正常使用解决方法

    CentOS 6.5 自带的Python 2.6.6 箭头以及退格键(Backspace)可正常使用: 自定义所安装的Python 2.7.6却发现箭头以及退格键(Backspace)在使用的时候出现 ...

  8. PHP学习之数据库操作

    PHP数据库操作: 一.连接数据库 mysql_connect() 例:$link=mysql_connent("localhost","root"," ...

  9. 一个基于MINA框架应用的最简单例子

    直接上代码.关于原理和主要的API以后在说.先能跑通了在说. 主要的包:mina-core-2.0.0.jar[到官网上下载完整项目包里面还有文档和依赖包],jcl-over-slf4j-1.5.11 ...

  10. urllib2.URLError: <urlopen error [Errno 104] Connection reset by peer>

    http://www.dianping.com/shop/8010173 File "综合商场1.py", line 152, in <module>    httpC ...