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: ...
随机推荐
- java @Autowired与@Resource的区别
@Autowired与@Resource的区别 1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. 2.@Autowired默认 ...
- php SimpleXML 例子
$txt = GetRemoteText($url); if(strlen($txt) > 0) { $xml = simplexml_load_string($txt); //获取xml if ...
- php utf-8字符转ascii字符
function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\ ...
- cvs update后输出的文件标志 和 update常用的几个参数
(1)update 和 checkout 在执行中,会为每个文件打印一行提示信息,文件的状态通过前面的单个字符指明: U file 文件按要求从仓库得到更新.用在那些仓库里面 ...
- 查找SQL SERVER被锁的表和解决方法
查找数据库中被锁表代码: select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName ...
- Win10光驱不见了
1. 网上教程试了很多,如下: http://jingyan.baidu.com/article/02027811656a8b1bcd9ce570.html http://jingyan.todgo. ...
- c#查找string数组的某一个值的索引
string[] array = { "A","B","C","D","H"}; var ind ...
- Linux:cacti环境部署
一.监控端安装1)基础软件:安装配置cacti前,需要安装:httpd.php.mysqld.php-mysql.net-snmp.rrdtool以上均可使用yum安装:yum install -y ...
- leetcode 205
205. Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are ...
- awk 命令
awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各 ...