用最少的矩阵覆盖n*m的地图。注意矩阵不能互相覆盖。

这里显然是一个精确覆盖,但因为矩阵拼接过程中,有公共的边,这里须要的技巧就是把矩阵的左边和以下截去一个单位。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
using namespace std;
const int maxnode = 550005;
const int MaxM = 999;
const int MaxN = 555;
int K,n,m;
void print(int x)
{printf("(%d %d)\n",x%(n+1)==0?

n:(x%(n+1)-1),x%(n+1)==0?

x/(n+1)-1:x/(n+1)); } struct DLX { int n,m,size; int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode]; int H[MaxN],S[MaxM]; int ands,ans[MaxN],ANS; void init(int _n,int _m) { ANS=0x3f3f3f3f; n = _n; m = _m; for(int i = 0; i <= m; i++) { S[i] = 0; U[i] = D[i] = i; L[i] = i-1; R[i] = i+1; } R[m] = 0; L[0] = m; size = m; for(int i = 1; i <= n; i++) H[i] = -1; } void Link(int r,int c) { ++S[Col[++size]=c]; Row[size] = r; D[size] = D[c]; U[D[c]] = size; U[size] = c; D[c] = size; if(H[r] < 0)H[r] = L[size] = R[size] = size; else { R[size] = R[H[r]]; L[R[H[r]]] = size; L[size] = H[r]; R[H[r]] = size; } } void remove(int c) { int i,j; L[R[c]]=L[c]; R[L[c]]=R[c]; for(i=D[c]; i!=c; i=D[i]) { for(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) { int i,j; for(i=U[c]; i!=c; i=U[i]) { for(j=L[i]; j!=i; j=L[j]) { U[D[j]]=j; D[U[j]]=j; S[Col[j]]++; } } L[R[c]]=c; R[L[c]]=c; } bool v[maxnode]; int f() { int ret = 0; for(int c = R[0]; c != 0; c = R[c])v[c] = true; for(int c = R[0]; c != 0; c = R[c]) if(v[c]) { ret++; v[c] = false; for(int i = D[c]; i != c; i = D[i]) for(int j = R[i]; j != i; j = R[j]) v[Col[j]] = false; } return ret; } void Dance(int d) { if(d+f()>=ANS) return; if(R[0] == 0) { ANS=min(ANS,d); return; } int c = R[0]; for(int i = R[0]; i != 0; i = R[i]) if(S[i] < S[c]) 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]); Dance(d+1); for(int j = L[i]; j != i; j = L[j])resume(Col[j]); } resume(c); } } g; int main() { int cas,x1,y1,x2,y2,k; scanf("%d",&cas); while(cas--) { scanf("%d%d%d",&n,&m,&k); g.init(k,n*m); for(int q=1; q<=k; q++) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); for(int i = x1+1; i <= x2; i++) for(int j = y1+1; j <= y2; j++) g.Link(q,j+(i-1)*m); } g.Dance(0); if(g.ANS==0x3f3f3f3f) g.ANS=-1; printf("%d\n",g.ANS); } return 0; }

转载于:https://www.cnblogs.com/gcczhongduan/p/5065507.html

ZOJ 3209 Treasure Map DLX相关推荐

  1. zoj 3209 Dancing links/hust 1017

    Dancing links的题目. 具体的dancing links的介绍 看:http://blog.csdn.net/sunny606/article/details/7833551 思想还是好理 ...

  2. Binbin's treasure map

    链接:https://ac.nowcoder.com/acm/contest/3674/C 来源:牛客网 题目描述 Binbin is a clever boy who likes to wear a ...

  3. Treasure Map ZOJ - 3209(Dancing Links)

    传送门 题解:首先可以先看下这篇对于Dancing Links的介绍,很好的传送门 然后这个题其实建模很简单的,把n*m的大矩阵转化成一排,然后把那些小矩阵对应起来,之后进行选取,如果可以选出最小集合 ...

  4. Binbin's treasure map(bfs)

    思路: #include <stdio.h> #include <iostream> #include <algorithm> using namespace st ...

  5. zoj 3629 Treasure Hunt IV

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4775 看yh大佬的课件的时候看到这题找规律的题,于是我就做了一下.原本我还想在 ...

  6. ZOJ ——3629 Treasure Hunt IV

    题意:整数N满足[n/1] + [n/2] + ... + [n/k] + ... 是偶数,则该数为特殊数字,给定一个区间[a,b],求其区间的特殊数字的个数. 解题思路:首先写一个暴力程序进行打表, ...

  7. DancingLinks刷题集

    HDU 3663 Power Stations 精确覆盖 题意:每个城市i有xi->yi天可以成为发射站,发射站覆盖范围为与该站有一条边链接的城市. 同时,每个每天城市必须且只能被一个发射站覆盖 ...

  8. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  9. 怎么添加新项目到svn服务器,用eclipse+svn插件,上传新项目到svn服务器

    mysql高可用架构之mysql-mmm配置详解 实验系统:CentOS 6.6_x86_64 实验前提:防火墙和selinux都关闭 实验说明:本实验共有5台主机,IP分配如拓扑 实验软件:mari ...

最新文章

  1. Nature子刊 | 研究人员提出神经脆性可作为癫痫发作区(SOZ)的脑电图(EEG)标志物
  2. 埃维诺任命杰出企业家郭秀闲掌舵大中华区业务
  3. ITK:用内核卷积图像
  4. (王道408考研操作系统)第一章计算机系统概述-第一节4:中断和异常
  5. 实用常识 | 分享一个好用的插件解决浏览器图片下载问题(老白嫖怪了)
  6. 37.Linux/Unix 系统编程手册(下) -- DAEMON
  7. wordpress之模板汉化(poedit的使用技巧 及 .po .mo 批量生成技术)
  8. idb的安装log及解决办法
  9. sqlmanager mysql5_SQL Manager for MySQL
  10. 高级前端面试题(来自一位朋友的投稿哟)
  11. 2021年软考考试时间确定
  12. 面试专家陈建军出二十一组面试题(转)
  13. 基于FPGA的SNR噪声分析
  14. Spring简化Java开发_java开发如何用spring简化?详细图解
  15. mplayer播放器,没有声音.
  16. CentOS7基于Hadoop 2.7.3安装Hive 2.1.1
  17. 研发投入资本化项目基本流程
  18. 「雅礼集训 2017 Day10」拍苍蝇
  19. GANSS 高斯 ALT71 使用说明
  20. 【产品】支付宝蚂蚁森林产品体验报告

热门文章

  1. 蓝桥每日真题之时间显示
  2. Codeforces 1114C(数论+唯一分解)
  3. 启动服务_用控制台启动一个wcf服务
  4. c++怎么可以在二进制文件中读取带string的数据_文件处理 | csv文件读写
  5. [人脸识别]什么叫One-shot learning
  6. window10查看内存情况
  7. 根据文件路径打开文件所在文件夹,并且默认选中该文件
  8. Loadrunner脚本函数
  9. chrome浏览器加载css、js等静态资源文件的坑
  10. 出现( linker command failed with exit code 1)错误总结