#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath> using namespace std;
#define N 230
#define MAXNODE 60000
const int INF = INT_MAX;
const double eps = 1e-; int n,m,n1,m1; struct DLX{
int n,m,size;
int U[MAXNODE] , D[MAXNODE] , L[MAXNODE] , R[MAXNODE];
int col[MAXNODE] , row[MAXNODE];
int first[N] , cnt_col[N] , ans;
bool v[MAXNODE]; void init(int _n , int _m)
{
n = _n , m = _m , size = _m;
for(int i= ; i<=m ; i++){
U[i] = D[i] = i;
L[i] = i- , R[i] = i+;
col[i] = i , row[i] = ;
}
L[] = m , R[m] = ;
for(int i= ; i<=n ; i++) first[i] = -;
for(int i= ; i<=m ; i++) cnt_col[i] = ;
ans = INF;
} void link(int r , int c)
{
++size;
U[D[c]] = size , D[size] = D[c];
U[size] = c , D[c] = size;
cnt_col[c]++; if(first[r]<) first[r] = L[size] = R[size] = size;
else{
R[size] = R[first[r]] , L[R[first[r]]] = size;
L[size] = first[r] , R[first[r]] = size;
}
row[size] = r , col[size] = c;
} void Remove(int c)
{
for(int i=D[c] ; i!=c ; i=D[i]){
L[R[i]] = L[i] , R[L[i]] = R[i];
}
} void Resume(int c)
{
for(int i=U[c] ; i!=c ; i=U[i]){
L[R[i]] = R[L[i]] = i;
}
} int f()
{
int ret = ;
for(int c=R[] ; c!= ; c=R[c]) v[c]=true;
for(int c=R[] ; c!= ; 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[]){
ans = min(ans , d);
return;
}
int st = R[];
for(int i=R[] ; i!= ; i=R[i])
if(cnt_col[st]>cnt_col[i]) st=i; for(int i=D[st] ; i!=st ; i=D[i]){
Remove(i);
for(int j=R[i] ; j!=i ; j=R[j]) Remove(j);
Dance(d+);
for(int j=L[i] ; j!=i ; j=L[j]) Resume(j);
Resume(i);
}
return;
}
}dlx; int mat[N][N] , id[N][N]; int main()
{
// freopen("a.in" , "r" , stdin);
while(~scanf("%d%d" , &n , &m))
{
int size = ;
for(int i= ; i<n ; i++)
for(int j= ; j<m ; j++)
{
scanf("%d" , &mat[i][j]);
//这里可以适当加优化,只保留那些有怪兽存在的位置
if(mat[i][j]) size++ , id[i][j] = size;
}
scanf("%d%d" , &n1 , &m1);
int t = (n-n1+)*(m-m1+); dlx.init(t , size);
for(int k= ; k<t ; k++){
int row = k/(m-m1+);
int col = k%(m-m1+);
for(int i=row ; i<row+n1 ; i++)
for(int j=col ; j<col+m1 ; j++)
if(mat[i][j]) dlx.link(k+ , id[i][j]);
}
dlx.Dance();
printf("%d\n" , dlx.ans);
}
return ;
}

FZU 1686 dlx重复覆盖的更多相关文章

  1. FZU 1686(重复覆盖)

    题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31370 题意:用尽量少r*c的小矩形覆盖大矩形n*m中的所有1,将 ...

  2. (中等) HDU 3335 , DLX+重复覆盖。

    Description As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory. ...

  3. HDU 2295.Radar (DLX重复覆盖)

    2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...

  4. hdu3656Fire station(DLX重复覆盖 + 二分)

    题目请戳这里 题目大意:一个城市n个点,现在要建m个消防站,消防站建在给定的n个点中.求建m个消防站后,m个消防站要覆盖所有的n个点的覆盖半径最小. 题目分析:重复覆盖问题,DLX解决.不过要求覆盖半 ...

  5. HDU 3957 Street Fighter (最小支配集 DLX 重复覆盖+精确覆盖 )

    DLX经典题型,被虐惨了…… 建一个2*N行3*N列的矩阵,行代表选择,列代表约束.前2*N列代表每个人的哪种状态,后N列保证每个人至多选一次. 显然对手可以被战胜多次(重复覆盖),每个角色至多选择一 ...

  6. HDU 5046 Airport【DLX重复覆盖】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意: 给定n个城市的坐标,要在城市中建k个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...

  7. hdu 2295 dlx重复覆盖+二分答案

    题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...

  8. [ACM] HDU 2295 Radar (二分法+DLX 重复覆盖)

    Radar Problem Description N cities of the Java Kingdom need to be covered by radars for being in a s ...

  9. (中等) HDU 4979 A simple math problem. , DLX+重复覆盖+打表。

    Description Dragon loves lottery, he will try his luck every week. One day, the lottery company brin ...

随机推荐

  1. 记一次有关spark动态资源分配和消息总线的爬坑经历

    问题: 线上的spark thriftserver运行一段时间以后,ui的executor页面上显示大量的active task,但是从job页面看,并没有任务在跑.此外,由于在yarn mode下, ...

  2. C#基础学习2

    变量与数据类型!

  3. java 替换字符串模板(模板渲染)

    java渲染字符串模板,也就是说在java字符串模板中设置变量字符串,使用变量去渲染指定模板中设置好的变量字符串.下面介绍4种替换模板方式: 1.使用内置String.format String me ...

  4. Java_静态变量

    class c1c { private static int num = 0; private static double pi = 3.14; private double radius; priv ...

  5. IOS的水滴文件效果

    @implementation ViewController - (void)viewDidLoad{ [super viewDidLoad]; NSDictionary *dict = [NSDic ...

  6. iOS猜拳游戏源码

    利用核心动画和Quartz2D做的一个小游戏.逻辑十分简单. 源码下载:http://code.662p.com/<ignore_js_op> 详细说明:http://ios.662p.c ...

  7. MongoDB最简单的入门教程之五-通过Restful API访问MongoDB

    通过前面四篇的学习,我们已经在本地安装了一个MongoDB数据库,并且通过一个简单的Spring boot应用的单元测试,插入了几条记录到MongoDB中,并通过MongoDB Compass查看到了 ...

  8. zabbix设置多个收件人

    1.建群组   2.添加群组权限   3.添加用户,归属到上面新建的组   4.动作里发送消息给新建的组   5.这样设置后,管理员账号不用设置收件媒介  

  9. docker 深入理解之namespace

    namespace 名称空间 docker容器主要通过资源隔离来实现的,应该具有的6种资源隔 namespace 的六项隔离 namespace 系统调用参数 隔离的内容 UTS CLONE_NEWU ...

  10. 激活函数:Swish: a Self-Gated Activation Function

    今天看到google brain 关于激活函数在2017年提出了一个新的Swish 激活函数. 叫swish,地址:https://arxiv.org/abs/1710.05941v1 pytorch ...