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. Setup a private http/nginx based GIT server

    原文:http://aaba.me/blog/2014/03/setup-a-private-http-nginx-based-git-server.html https://doomzhou.git ...

  2. 【转】linux ls -l的详解

    原文:http://blog.csdn.net/sjzs5590/article/details/8254527 以root的家目录为例: 可以看到,用ls -l命令查看某一个目录会得到一个7个字段的 ...

  3. 安装MSYS2过程遇到的问题及解决记录

    1.在安装结束后按照官方教程开始更新系统是遇到了如下的错误 could not open file /var/lib/pacman/sync/msys32.db: Unrecognized archi ...

  4. WPF(x:Null 使用)

    <Window x:Class="TestOfNull.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...

  5. Debian 安装Nvidia显卡驱动

    1.到nvidia官方网站下载自己显卡对应型号得驱动,如果不知道显卡型号,可以使用如下命令来查看 lspci | grep VGA 2.安装显卡驱动所必需得工具 apt-get install bui ...

  6. windows程序设计(四)

    对话框常用相关消息映射函数: 一.对话框初始化消息: 1.WM_CREATE:通用窗口初始化消息 窗口还未显示出来,只有父窗口,子窗口还没创建 2.WM_INITDIALOG:对话框窗口专用消息 子窗 ...

  7. js滚动条

    /*滚动条在Y轴上的滚动距离*/function ScrollTop(){ var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0; i ...

  8. The Accumulation of Capital

    The Accumulation of Capital ---- by *Adam Smith Capitals are increased by parsimony, and diminished ...

  9. memcache command

    http://www.cnblogs.com/jeffwongishandsome/archive/2011/11/06/2238265.html

  10. launchMode 和 onNewIntent 关系 任务栈知识.

    onNewIntent(Intent intent). 的调用时候.  当启动一个activity时候,如果launchMode是singletop. 或者 singletask,活着singleIn ...