ZOJ 3209 Treasure Map(Dancing Links)(精确覆盖问题)

VS2017配置PCL1.9.1 for win10(超详细) 准备工作 VS2017 自行下载 PCL1.9.1 点击链接跳转Github下载,根据自己的环境选择 win64或win32,作者下载的是:PCL-1.9.1-AllInOne-msvc2017-win64.exepcl-1.9.1-pdb-msvc2017-win64.zip 安装PCL 双击点开PCL-1.9.1-AllInOne-msvc2017-win64.exe,选择Add PCL to the system PATH for all users, 更改安装路径,E:\Progra 阅读详情

Treasure Map

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3209

解题思路:

题目大意:

给你一个n*m的矩形,有p个小矩形,问你用这些小矩形(不允许重复)最多可以拼多少个n*m的矩形。

算法思想:

Dancing Links.

把每个格子当成一个列,然后覆盖所有格子。问题就转为了:精确覆盖问题。

AC代码:

#include <iostream>
#include <cstdio>
using namespace std;

const int maxnode = 100010;
const int maxm = 1010;
const int maxn = 1010;

struct DLX{
    int n,m,len;
    int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
    int H[maxn];//行头结点
    int S[maxm];//每列有多少个结点
    int ansd,ans[maxn];//如果有答案,则选了ansd行,具体是哪几行放在ans[]数组里面,ans[0~ansd-1]

    void init(int _n,int _m){
        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;
        len = m;//编号,每列都有一个头结点,编号1~m
        for(int i = 1; i <= n; i++)
            H[i] = -1;//每一行的头结点
    }

    void link(int r,int c){//第r行,第c列
        ++S[Col[++len]=c];//第len个节点所在的列为c,当前列的结点数++
        Row[len] = r;//第len个结点行位置为r
        D[len] = D[c];
        U[D[c]] = len;
        U[len] = c;
        D[c] = len;
        if(H[r] < 0)
            H[r] = L[len] = R[len] = len;
        else{
            R[len] = R[H[r]];
            L[R[H[r]]] = len;
            L[len] = H[r];
            R[H[r]] = len;
        }
    }

    void del(int c){//删除结点c,以及c上下结点所在的行
        //每次调用这个函数,都是从列头节点开始向下删除,这里c也可以理解为第c列
        //因为第c列的列头节点编号为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){//回复结点c,以及c上下节点所在的行(同上,也可以理解为从第c列的头节点开始恢复
        for(int i = U[c]; i != c; i = U[i]){
            for(int j = L[i]; j != i; j = L[j]){
                ++S[Col[U[D[j]]=D[U[j]]=j]];
            }
        }
        L[R[c]] = R[L[c]] = c;
    }

    void dance(int d){//递归深度
        //剪枝
        if(ansd != -1 && ansd <= d)
            return;
        if(R[0] == 0){
            if(ansd == -1)
                ansd = d;
            else if(d < ansd)
                ansd = d;
            return ;
        }
        int c = R[0];
        for(int i = R[0]; i != 0; i = R[i]){
            if(S[i] < S[c])
                c = i;
        }

        del(c);//找到结点数最少的列,当前元素不是原图上0,1的节点,而是列头节点
        for(int i = D[c]; i != c; i = D[i]){
            ans[d] = Row[i];//列头节点下面的一个节点
            for(int j = R[i]; j != i; j = R[j])
                del(Col[j]);
            dance(d+1);
            for(int j = L[i]; j != i; j = L[j])
                resume(Col[j]);
        }
        resume(c);
    }
};

DLX head;

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m,p;
        scanf("%d%d%d",&n,&m,&p);
        head.init(p,n*m);
        int x1,y1,x2,y2;
        for(int k = 1; k <= p; k++){
            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++){
                    head.link(k,(i-1)*m+j);
                }
            }
        }
        head.ansd = -1;
        head.dance(0);
        printf("%d\n",head.ansd);
    }
    return 0;
}


MC_SetOverride指令详细应用介绍(基恩士PLC) 基恩士KV系列PLC和松下总线绝对值伺服运动控制(详细配置+轴控完整ST源代码) 阅读详情

相关推荐

wsl2上运行带有Isaac Gym的程序报错: GPU Pipeline: disabled

显示GPU Pipeline:disabled,查找相关文档发现是WSL2目前不支持Isaac Gym,时,想要在wsl2上运行,最后报错如下。

2303_78660611的博客 956

ZOJ 3209 Treasure Map

ZOJ 3209 Treasure Map 题目链接 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 posi

旺崽的博客 2653

「免费开源」从 OCR 识别到结构化输出:合同文本高效比对的完整解决方案!

本文将系统拆解这一解决方案的技术逻辑、实施步骤与落地价值,为企业合同管理数字化转型提供实操指南。字段提取:自动识别并提取预设的关键字段(如 “甲方”“乙方”“合同金额”“履约期限” 等),若遇到模糊表述(如 “付款时间为合同签订后 30 个工作日内”),系统可自动解析为 “履约期限:合同签订日 + 30 工作日”;预设结构化字段:根据合同类型(如采购合同、服务合同、租赁合同),定义需提取的关键字段(如 “甲方名称”“乙方名称”“合同金额”“有效期起 / 止日期”“履约地点”“违约金比例” 等);

qxsz_yyh的博客 835

ZOJ-3209 Treasure Map(dancing links,舞蹈链算法,DLX)

ZOJ - 3209 题目描述 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. L...

int_Brosea的博客 577

ESP32S3 Korvo2V3四通道AEC配置实战:基于AFE的回声消除优化

本文详细介绍了在ESP32S3 Korvo2V3平台上配置四通道AEC(回声消除)的实战经验。通过AFE算法优化和硬件连接调试,实现高质量回声消除,显著提升智能音箱和会议设备的语音交互体验。重点解析了四通道配置、数据格式对齐和参数调优等关键技术要点。

elastic6hunter的博客 932

【国民技术N32项目移植】基于 Windows 的 ARM GCC 开发环境

【国民技术N32项目移植】基于 Windows 的 ARM GCC 开发环境

weixin_42150032的博客 1355

ZOJ 3209 Treasure Map【DancingLink】

ZOJ 3209 Treasure Maphttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3372大意:已知有一张n*m的图,p个矩形,问至少需要多少个矩形能够完全覆盖整幅图, 要求不能出现重叠分析: 转化为精确铺盖问题,即将图拉成一条长度为n*m的链,在该图中找到每个矩形 对应的覆盖点,用Dancing...

a48634331的博客 200

Python爬虫实战:逆向解析央视频加密参数(附完整代码)

本文详细解析了央视频加密体系的技术实现,通过Python逆向工程实战演示如何解密动态密钥、AES加密和自定义哈希算法等核心组件。文章提供完整代码示例,涵盖GUID生成、参数构造和异步请求处理,帮助开发者掌握现代视频平台的反爬机制破解方法。

weixin_42532473的博客 1128

ZOJ 3209 Treasure Map(精确覆盖)

Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, and

Dacc123的博客 547

【ComfyUI报错解决】K采样器 mat1和mat2形状不匹配错误分析与修复 mat1 and mat2 shapes cannot be multiplied (77x2048 and 4096x

如果你在 ComfyUI 里遇到K采样器报错:mat1 和 mat2 shapes cannot be multiplied确认大模型和 LoRA 是否是同一版本(SDXL vs SD1.5,不能混用)。如果用了双 CLIP 加载器,要确认加载的类型和选择的模型类型是否匹配。加载→ 类型选flux加载 SDXL 专用的 clip/t5 → 类型选sdxl避免不同版本模型和 LoRA 混搭,保持一致性。模型+LoRA+CLIP 类型必须保持同一版本,不然就会报错。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 2407

抖音中动态生成msToken的方法

抖音中动态生成msToken的方法

sh_moranliunian的博客 2483

zoj 3209 Treasure Map 最小覆盖问题 dancing links

这是练手的一道dancing links题,直接套用上篇博文那题的代码即可,不过得把问题稍微转化以下。 地图是个m行n列的地图,即有n*m个小块,共有p个图片去覆盖,那么我们只要找出每个小块和p个图片的关系,构造一个p行n*m列的矩阵,那么第j行第j列表示,j对应的那个小块能被图片i覆盖 剩下的问题,就是如何选出最少的行数使得每列被覆盖即可(可以参见上一篇文章 http://blog.cs

renew 1126

Python爬虫-爬取猫眼演出数据

本文是该专栏的第53篇,后面会持续分享python爬虫干货知识。猫眼平台除了有影院信息之外,它还涵盖了演出信息,比如说“演唱会,音乐节,话剧音乐剧,脱口秀,音乐会,戏曲艺术,相声”等等各种演出相关信息。而本文,笔者将以猫眼平台为例,基于Python爬虫实现获取各种演出信息的数据。废话不多说,具体细节部分以及详细思路逻辑,笔者将在正文结合完整代码进行详细说明。(附带完整代码)

Python进阶专栏《爬虫实战进阶》,《Pyppeteer从入门到精通》原创作者 568

ZOJ3209 Treasure Map —— Danc Links 精确覆盖

题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of a treasure map. Unfortunately, all the copi

A man can be destroyed, but not defeated. 634

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

ZOJ 3209 Treasure Map(精确覆盖问题&舞蹈链)

题目链接:[kuangbin带你飞]专题三 Dancing Links B - Treasure Map题意 给一矩形和k个小矩形,问选取最小数量为多少的小矩形可以对大矩形进行精确覆盖。 思路 仍然是个模版题,把二维的n*m的大矩形看作是一维的n*m的一条线。k个小矩形同理,那么就转化成01矩阵精确覆盖的问题了。 代码#include <iostream> #include <algorit

YiShi's Blog 1912

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

[kuangbin]专题三 Dancing Links Treasure Map ZOJ - 3209【精确覆盖】

【题目描述】 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, i...

inv0ker的博客 286

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

ZOJ 3209 Treasure Map(Dancing Links)

题意:给出一个地图和若干碎片,现在要选取最少的碎片恢复地图,求最少的碎片数量。 思路:将每一个格子视为原来的一个列属性,有这一个格子的碎片这一列就为1,也就是说将这个二维的问题转化为了一个一维的dlx的问题,然后套模板求解即可。 #include #include #include #include #include #include #include #include #include #i

GODSPEED 509

ZOJ3209 Treasure Map(Dancing Links)

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. Lucki

MrBlank的ACM记事本 351

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

题意 :  给你一个大小为 n * m 的矩形 , 坐标是( 0 , 0 ) ~ ( n , m )  。然后给你 p 个小矩形 , 坐标是( x1 , y1 ) ~ ( x2 , y2 ) , 你选择最小的几个矩形 , 使得这些矩形可以覆盖整个矩形 , 并且互相不会重叠 。( n , m 思路 : Dancing Links 的精确覆盖问题 。 我们将 n * m 的矩形分成 n * m

Lisz的专栏 733

[ACM] ZOJ 3209 Treasure Map ( Dancing Links 精确覆盖,矩形覆盖)

Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, an

逆风的方向 更适合飞翔 2831

zoj 3209 Treasure Map(dancing links 精准覆盖问题)

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 po...

ling_wang的博客 486

zoj3209Treasure Map【dancing links】

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. Lu

MissZhou要努力 447

zoj 3209 Treasure Map (dancing links)

裸= = 模板题。只需要建图的时候注意一下。 #include #include #include #include #define maxn 505*909 #define inf 0x3f3f3f3f using namespace std; int n,m,p; int map[505][909]; int L[maxn],R[maxn],D[maxn],U[maxn]

Jinx Jinx again 722

ZOJ 3209 Treasure Map (Dancing Links)

Treasure MapTime Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, and what m...

weixin_34290096的博客 200

zoj 3209 Treasure Map dancing links

题意:在给定的矩形中,选取最少的矩形数量,使之给定的能覆盖(n*m)矩形 思路:我们把题目给的q个矩形,对与每一个矩形,划分成1*1的小矩形,面积为a*b的矩形就能划分成a*b个(1*1)的小矩形,(n*m)矩形看成所有的列,每一个给定的矩形都看成行,那么就是一个精确覆盖问题。直接上白书模板,还有些小细节,看代码 #include #include #include #i

zyh 580

zoj 3209 Treasure Map 精确覆盖 DLX 给一些指定位置的矩形,使用最少的矩形去精确覆盖一个大的矩形,矩形间不能重叠。

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

kongming_acm的专栏 525
上一篇: HUST 1017 Exact cover(Dancing Links)(精确覆盖问题)
下一篇: hdu 1166 敌兵布阵
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值