FZU 1686 神龙的难题 (重复覆盖)
Accept: 397 Submit: 1258
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
这是个剑与魔法的世界.英雄和魔物同在,动荡和安定并存.但总的来说,库尔特王国是个安宁的国家,人民安居乐业,魔物也比较少.但是.总有一些魔物不时会进入城市附近,干扰人民的生活.就要有一些人出来守护居民们不被魔物侵害.魔法使艾米莉就是这样的一个人.她骑着她的坐骑,神龙米格拉一起消灭干扰人类生存的魔物,维护王国的安定.艾米莉希望能够在损伤最小的前提下完成任务.每次战斗前,她都用时间停止魔法停住时间,然后米格拉他就可以发出火球烧死敌人.米格拉想知道,他如何以最快的速度消灭敌人,减轻艾米莉的负担.
Input
数据有多组,你要处理到EOF为止.每组数据第一行有两个数,n,m,(1<=n,m<=15)表示这次任务的地区范围. 然后接下来有n行,每行m个整数,如为1表示该点有怪物,为0表示该点无怪物.然后接下一行有两个整数,n1,m1 (n1<=n,m1<=m)分别表示米格拉一次能攻击的行,列数(行列不能互换),假设米格拉一单位时间能发出一个火球,所有怪物都可一击必杀.
Output
输出一行,一个整数,表示米格拉消灭所有魔物的最短时间.
Sample Input
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1
2 2
4 4
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0
2 2
Sample Output
1
Source
FOJ月赛-2009年2月- TimeLoop
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1686
重复覆盖模板题。
1为列,可以操作的为行
/* ***********************************************
Author :kuangbin
Created Time :2014/5/27 17:53:47
File Name :E:\2014ACM\专题学习\DLX\FZU1686.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MaxM = *+;
const int MaxN = *+;
const int maxnode = MaxN * MaxM;
const int INF = 0x3f3f3f3f;
struct DLX
{
int n,m,size;
int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
int H[MaxN],S[MaxM];
int ansd;
void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
size = m;
for(int i = ;i <= n;i++)H[i] = -;
}
void Link(int r,int c)
{
++S[Col[++size]=c];
Row[size] = r;
D[size] = D[c];
U[D[c]] = size;
U[size] = c;
D[c] = size;
if(H[r] < )H[r] = L[size] = R[size] = size;
else
{
R[size] = R[H[r]];
L[R[H[r]]] = size;
L[size] = H[r];
R[H[r]] = size;
}
}
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;
}
bool v[MaxM];
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() >= ansd)return;
if(R[] == )
{
if(d < ansd)ansd = d;
return;
}
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;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);
}
}
};
DLX g; int a[][];
int id[][]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
while(scanf("%d%d",&n,&m) == )
{
int sz = ;
memset(id,,sizeof(id));
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j] == )id[i][j] = (++sz);
}
g.init(n*m,sz);
sz = ;
int n1,m1;
scanf("%d%d",&n1,&m1);
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
{
for(int x = ;x < n1 && i + x < n;x++)
for(int y = ;y < m1 && j + y < m;y++)
if(id[i+x][j+y])
g.Link(sz,id[i+x][j+y]);
sz++;
}
g.ansd = INF;
g.Dance();
printf("%d\n",g.ansd);
}
return ;
}
FZU 1686 神龙的难题 (重复覆盖)的更多相关文章
- FZU Problem 1686 神龙的难题 重复覆盖
题目链接 给出大矩形的长宽, 矩形里面有1,0两个值, 给出小矩形的长宽, 求用最少的小矩形覆盖所有的1. 重复覆盖的模板题. #include <iostream> #include & ...
- FZU 1686 神龙的难题(DLX反复覆盖)
FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...
- FZU 1686 神龙的难题 DLX反复覆盖
DLX反复覆盖: 须要一个A*函数剪支 Problem 1686 神龙的难题 Accept: 462 Submit: 1401 Time Limit: 1000 mSec Memory L ...
- [ACM] FZU 1686 神龙的难题 (DLX 反复覆盖)
Problem 1686 神龙的难题 Accept: 444 Submit: 1365 Time Limit: 1000 mSec Memory Limit : 32768 KB Pro ...
- (简单) FZU 1686 神龙的难题 , DLX+可重复覆盖。
Description 这是个剑与魔法的世界.英雄和魔物同在,动荡和安定并存.但总的来说,库尔特王国是个安宁的国家,人民安居乐业,魔物也比较少.但是.总有一些魔物不时会进入城市附近,干扰人民的生活.就 ...
- FZU 1686 神龙的难题 (DLX)
神龙的难题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- FZU 1686 龙之谜 重复覆盖
兑换0,1模型,如.注意,数据的范围 #include <stdio.h> #include <string.h> #include <iostream> #inc ...
- FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena
告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...
- FZU1686 神龙的难题 —— Dancing Links 可重复覆盖
题目链接:https://vjudge.net/problem/FZU-1686 Problem 1686 神龙的难题 Accept: 812 Submit: 2394 Time Limit: ...
随机推荐
- C++设计模式-Strategy策略模式
Strategy策略模式作用:定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. UML图: Strategy模式将逻辑(算法)封装到一个类(Cont ...
- firebug常用工具
1.console.group("第一组"); console.log(1); console.groupend(); 2.console.dir(对象);//输出对象的所有信息 ...
- html, xhtml和xml
html, xhtml和xml 1.定义及特点: 1) html:Hyper Text Markup Language 超文本标记语言 是最早写网页的语言,但编码不规范,主要用于控制数据的显示和外观. ...
- I/O系统 (输入/输出)
I/O系统 1:流: (1)判断到底是输入,还是输出:永远站在程序的立场上: (2)判断传递的到底是字节还是字符,从而决定管道的粗细: 字节管道可以传递所有数据,字符管道专门用来传递文本数据(1个字符 ...
- clipboard_monitor_in_win7
添加监听 AddClipboardFormatListener(this.Handle); 移除 RemoveClipboardFormatListener(this.Handle); #region ...
- 关于conky
- Windows程序设再读笔记03-窗口与消息
1.关于LoadIcon/LoadCursor,这两个函数,第一个参数为实例句柄,如果是从保存在磁盘中的可执行文件中加载资源,则需要则需要指定可执行文件的hInstance,如果是系统资源,该句柄为N ...
- java System.getProperty()参数大全
java.version Java Runtime Environment versionjava.vendor Java Runtime Environment vendorjava.vendor. ...
- 转 Selenium+Python+Eclipse网页自动化集成环境配置(附简单的测试程序)
1 JDK.Python环境变量配置 下载JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html,直接双击安装, ...
- SQLServer : EXEC和sp_executesql的区别
MSSQL为我们提供了两种动态执行SQL语句的命令,分别是EXEC和sp_executesql.通常,sp_executesql则更具有优势,它提供了输入输出接口,而EXEC没有.还有一个最大的好处就 ...