#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. Hadoop工作流--ChainMapper/ChainReducer?(三)

    不多说,直接上干货! Hadoop的ChainMapper和ChainReducer使用案例(链式处理) 什么是ChainMapper/ChainReducer?

  2. 【前端】jQurey Plugin

    ; (function ($, window, document, undefined) { "use strict"; var defaults = { name: " ...

  3. 原创 Repeater radio 单选和多选混合

    希望高手朋友给我留下美好的意见,在此先感谢您! 前台代码repeater: <script src="../Scripts/jquery-1.9.1.js"></ ...

  4. AJPFX总结抽象类和接口的区别

    /*                 * 抽象类和接口的区别                 *                 1.成员的区别                         *   ...

  5. PetStore项目总结

    数据库(MySQL): account(用户表:没有外键), profile(用户侧面信息表:有两个外键:catid,username), category(宠物总分类表--鱼:没有外键), prod ...

  6. CF749C Voting

    题目链接: http://codeforces.com/problemset/problem/749/C 题目大意: 共有n个人,编号为1~n.他们每个人属于且仅属于R阵营或N阵营中的一个.现在他们要 ...

  7. HYSBZ 1588 营业额统计 (Splay树)

    题意:给出一个公司每一天的营业额,求每天的最小波动值之和.该天的最小波动值= min { 绝对值| 该天以前某一天的营业额-该天的营业额 | }.第一天的最小波动值就是其自己. 思路:Splay伸展树 ...

  8. TIOJ1208 第K大连续和

    第k大的题一般都有点麻烦 pbds库的tree,需要研究一下https://codeforces.com/blog/entry/11080find_by_order() and order_of_ke ...

  9. k8s集群部署之环境介绍与etcd数据库集群部署

    角色 IP 组件 配置 master-1 192.168.10.11 kube-apiserver kube-controller-manager kube-scheduler etcd 2c 2g ...

  10. Java数据结构和算法(一)--栈

    栈: 英文名stack,特点是只允许访问最后插入的那个元素,也就是LIFO(后进先出) jdk中的stack源码: public class Stack<E> extends Vector ...