ZOJ 3209 Treasure Map DLX精确覆盖
来源:互联网 发布:2016年nba总决赛g4数据 编辑:程序博客网 时间:2024/05/16 17:15
题目:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3209
题意:
有一个n*m的矩形,现在有p个碎片,每个碎片精确的覆盖某个区域,问最少需要多少碎片可以恰好覆盖这个矩形,要求任意碎片之间不能有重叠的部分
思路:
可以发现矩形的范围比较小,那么把矩形内的点都抽象出来,碎片内的点都抽象出来,碎片内的覆盖对应的矩形中的点,就是精确覆盖问题了。
#include <bits/stdc++.h>using namespace std;const int X = 500000 + 10, N = 500 + 10, M = 1000 + 10, INF = 0x3f3f3f3f;int res;struct DLX{ int U[X], D[X], L[X], R[X], row[X], col[X]; int H[N], S[M]; int head, sz, tot, n, m, ans[N]; void init(int _n, int _m) { n = _n, m = _m; for(int i = 0; i <= m; i++) L[i] = i-1, R[i] = i+1, U[i] = D[i] = i, S[i] = 0; head = 0, tot = 0, sz = m; L[head] = m, R[m] = head; for(int i = 1; i <= n; i++) H[i] = -1; } void link(int r, int c) { ++S[col[++sz]=c]; row[sz] = r; D[sz] = D[c], U[D[c]] = sz; U[sz] = c, D[c] = sz; if(H[r] < 0) H[r] = L[sz] = R[sz] = sz; else R[sz] = R[H[r]], L[R[H[r]]] = sz, L[sz] = H[r], R[H[r]] = sz; } void del(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]) D[U[j]] = D[j], U[D[j]] = U[j], --S[col[j]]; } void recover(int c) { for(int i = U[c]; i != c; i = U[i]) for(int j = L[i]; j != i; j = L[j]) D[U[j]] = U[D[j]] = j, ++S[col[j]]; R[L[c]] = L[R[c]] = c; } void dance(int dep) { if(R[head] == head) { res = min(res, dep-1); return; } if(dep-1 >= res) return; int c = R[head]; for(int i = R[head]; i != head; i = R[i]) if(S[i] < S[c]) c = i; del(c); for(int i = D[c]; i != c; i = D[i]) { ans[dep] = row[i]; for(int j = R[i]; j != i; j = R[j]) del(col[j]); dance(dep + 1); for(int j = L[i]; j != i; j = L[j]) recover(col[j]); } recover(c); }}dlx;int main(){ int t, n, m, p; scanf("%d", &t); while(t--) { scanf("%d%d%d", &n, &m, &p); dlx.init(p, n * m); int x1, y1, x2, y2; for(int i = 1; i <= p; i++) { scanf("%d%d%d%d", &x1, &y1, &x2, &y2); for(int j = x1+1; j <= x2; j++) for(int k = y1+1; k <= y2; k++) { dlx.link(i, (j-1)*m + k); } } res = INF; dlx.dance(1); if(res == INF) res = -1; printf("%d\n", res); } return 0;}
阅读全文
0 0
- DLX (精确覆盖) ZOJ 3209 Treasure Map
- ZOJ 3209 Treasure Map(DLX精确覆盖)
- ZOJ 3209 Treasure Map (DLX精确覆盖)
- ZOJ 3209 Treasure Map DLX精确覆盖
- zoj - 3209 - Treasure Map(精确覆盖DLX)
- ZOJ 3209 Treasure Map(DLX精确覆盖)
- ZOJ 3209 Treasure Map (DLX精确覆盖)
- ZOJ 3209 Treasure Map (DLX精确覆盖问题)
- ZOJ 3290 Treasure Map(DLX+精确覆盖)
- ZOJ-3209-Treasure Map【6th浙江省赛】【DLX精确覆盖】【模板题】
- ZOJ 3209 Treasure Map(精确覆盖)
- DLX精确覆盖 zoj3209 Treasure Map
- ZOJ3209 Treasure Map(DLX精确覆盖)
- ZOJ 3209 Treasure Map DLX
- ZOJ 3209 Treasure Map (Dancing Links 精确覆盖 )
- ZOJ 3209 Treasure Map(精确覆盖问题&舞蹈链)
- [ZOJ]3209 Treasure Map 跳舞链 精确覆盖
- 舞蹈链..Exact cover&Treasure Map等 . DLX-精确覆盖
- OSI的七层模型详解
- 受不了现在的自己
- BPS计划功能出口的数据处理
- linux系统下性能调试工具。
- 【Noip2013】生活大爆炸版石头剪刀布
- ZOJ 3209 Treasure Map DLX精确覆盖
- python小程序-简易计算器
- Ng-ML|第七周SVM
- UVALive
- IE8下input框设置成readonly后仍然有光标
- PyCharm使用技巧记录(一)如何查看变量
- 打擂法
- android SElinux 总结--启用,关闭以及配置文件说明,很详细,值得学习
- javase-函数(方法)