Description

  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. Luckily, it is possible to figure out the position of each piece in the original map. Now the boss asks you, the talent programmer, to make a complete treasure map with these pieces. You need to make only one complete map and it is not necessary to use all the pieces. But remember, pieces are not allowed to overlap with each other (See sample 2).

  题目就是找到几个矩形来覆盖一个大的矩形,而且要求不能重叠。

  构造01矩阵的话就是把n*m这个大矩形的每一个点都作为一列(也就是有n*m列),然后把每一个可选择矩形都当做一行。。。

代码如下:

#include<iostream>
#include<cstring> using namespace std; const int INF=10e8;
const int MaxN=;
const int MaxM=*;
const int MaxNode=*+; struct DLX
{
int n,m,size;
int U[MaxNode],D[MaxNode],L[MaxNode],R[MaxNode],col[MaxNode];
int S[MaxM],H[MaxN];
int ans; void init(int _n,int _m)
{
n=_n;
m=_m; ans=INF; for(int i=;i<=m;++i)
{
S[i]=;
U[i]=D[i]=i;
L[i]=i-;
R[i]=i+;
}
L[]=m;
R[m]=; size=m; for(int i=;i<=n;++i)
H[i]=-;
} void Link(int r,int c) //r is row , c is col.
{
col[++size]=c;
++S[c]; U[size]=U[c];
D[U[c]]=size;
D[size]=c;
U[c]=size; if(H[r]<)
H[r]=L[size]=R[size]=size;
else
{
R[size]=H[r];
L[size]=L[H[r]];
R[L[H[r]]]=size;
L[H[r]]=size;
}
} void remove(int c)
{
R[L[c]]=R[c];
L[R[c]]=L[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 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]]=U[D[j]]=j;
} R[L[c]]=L[R[c]]=c;
} void Dance(int d)
{
if(R[]==)
{
if(d<ans)
ans=d; return;
} if(d>ans)
return; int c=R[]; for(int i=R[];i!=;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+); for(int j=L[i];j!=i;j=L[j])
resume(col[j]);
} resume(c);
}
}; DLX dlx; int main()
{
ios::sync_with_stdio(false); int T;
int n,m,p;
int x1,x2,y1,y2;
cin>>T; while(T--)
{
cin>>n>>m>>p; dlx.init(p,(n)*(m)); for(int i=;i<=p;++i)
{
cin>>x1>>y1>>x2>>y2; for(int x=x1;x<x2;++x)
for(int y=y1;y<y2;++y)
dlx.Link(i,y*(n)+x+);
} dlx.Dance(); if(dlx.ans==INF)
cout<<-<<endl;
else
cout<<dlx.ans<<endl;
} return ;
}

(简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。的更多相关文章

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

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

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

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

  3. ZOJ 3209 Treasure Map DLX

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

  4. (简单) HUST 1017 Exact cover , DLX+精确覆盖。

    Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...

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

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

  6. ZOJ 3209 Treasure Map 精确覆盖

    题目链接 精确覆盖的模板题, 把每一个格子当成一列就可以. S忘记初始化TLE N次, 哭晕在厕所...... #include<bits/stdc++.h> using namespac ...

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

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

  8. ZOJ 3209 Treasure Map (Dancing Links)

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

  9. ZOJ 3209 Treasure Map (Dancing Links)

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

随机推荐

  1. java中json数据生成和解析(复杂对象演示)

    1.json简单介绍 1.1 json是最流行和广泛通用的数据传输格式,简称JavaScript Object Notation,最早在JavaScript中使用. 1.2 举个例子,下面是一个jso ...

  2. SELinux(Security-Enhanced Linux)

    http://blog.csdn.net/myarrow/article/details/9839377 Security-Enhanced Linux(SELinux)的历史 一个小历史将有助于帮助 ...

  3. jquery带小图的图片轮换效果

    右边显示大图,左边显示小图 <style> ul{ list-style:none; padding:0px; margin:0px;} li{ list-style:none; padd ...

  4. JSP中文编码问题

    这个乱码问题是最简单的乱码问题.一般新会出现.就是页面编码不一致导致的乱码. <%@ page language="java" pageEncoding="UTF- ...

  5. 在Android studio中进行NDK开发

     在Android studio中进行NDK开发  分类: Android平台 软硬件环境 ubuntu kylin 14.04 红米note增强版 Android studio 0.8.6 ndk ...

  6. 第一个python实例程序

    #!/usr/bin/python2.7 import os ls = os.linesep fname = raw_input("fname:"); while True: if ...

  7. java 集合大家族

    在编写java程序中,我们最常用的除了八种基本数据类型,String对象外还有一个集合类,在我们的的程序中到处充斥着集合类的身影!java中集合大家族的成员实在是太丰富了,有常用的ArrayList. ...

  8. asp读取指定目录下的文件名

    bianli(Server.MapPath("/")+"\pic") InStrRev("abcd.jpg", ".") ...

  9. View与ViewGroup有什么区别?

    百度知道:http://zhidao.baidu.com/link?url=B5MFOzDlww8soYqr5CL5FldH4sXD6eumS1XTRn8XEh8gu4mKjQdPkJSLIBt7u_ ...

  10. logstash安装配置

    vim /usr/local/logstash/etc/hello_search.conf 输入下面: input { stdin { type => "human" }} ...