Problem 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

4 4
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

4
1

 Source

FOJ月赛-2009年2月- TimeLoop

题目链接:http://acm.fzu.edu.cn/problem.php?pid=1686

重复覆盖模板题。

1为列,可以操作的为行

  1. /* ***********************************************
  2. Author :kuangbin
  3. Created Time :2014/5/27 17:53:47
  4. File Name :E:\2014ACM\专题学习\DLX\FZU1686.cpp
  5. ************************************************ */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <iostream>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <string>
  16. #include <math.h>
  17. #include <stdlib.h>
  18. #include <time.h>
  19. using namespace std;
  20. const int MaxM = *+;
  21. const int MaxN = *+;
  22. const int maxnode = MaxN * MaxM;
  23. const int INF = 0x3f3f3f3f;
  24. struct DLX
  25. {
  26. int n,m,size;
  27. int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
  28. int H[MaxN],S[MaxM];
  29. int ansd;
  30. void init(int _n,int _m)
  31. {
  32. n = _n;
  33. m = _m;
  34. for(int i = ;i <= m;i++)
  35. {
  36. S[i] = ;
  37. U[i] = D[i] = i;
  38. L[i] = i-;
  39. R[i] = i+;
  40. }
  41. R[m] = ; L[] = m;
  42. size = m;
  43. for(int i = ;i <= n;i++)H[i] = -;
  44. }
  45. void Link(int r,int c)
  46. {
  47. ++S[Col[++size]=c];
  48. Row[size] = r;
  49. D[size] = D[c];
  50. U[D[c]] = size;
  51. U[size] = c;
  52. D[c] = size;
  53. if(H[r] < )H[r] = L[size] = R[size] = size;
  54. else
  55. {
  56. R[size] = R[H[r]];
  57. L[R[H[r]]] = size;
  58. L[size] = H[r];
  59. R[H[r]] = size;
  60. }
  61. }
  62. void remove(int c)
  63. {
  64. for(int i = D[c];i != c;i = D[i])
  65. L[R[i]] = L[i], R[L[i]] = R[i];
  66. }
  67. void resume(int c)
  68. {
  69. for(int i = U[c];i != c;i = U[i])
  70. L[R[i]] = R[L[i]] = i;
  71. }
  72. bool v[MaxM];
  73. int f()
  74. {
  75. int ret = ;
  76. for(int c = R[]; c != ;c = R[c])v[c] = true;
  77. for(int c = R[]; c != ;c = R[c])
  78. if(v[c])
  79. {
  80. ret++;
  81. v[c] = false;
  82. for(int i = D[c];i != c;i = D[i])
  83. for(int j = R[i];j != i;j = R[j])
  84. v[Col[j]] = false;
  85. }
  86. return ret;
  87. }
  88. void Dance(int d)
  89. {
  90. if(d + f() >= ansd)return;
  91. if(R[] == )
  92. {
  93. if(d < ansd)ansd = d;
  94. return;
  95. }
  96. int c = R[];
  97. for(int i = R[];i != ;i = R[i])
  98. if(S[i] < S[c])
  99. c = i;
  100. for(int i = D[c];i != c;i = D[i])
  101. {
  102. remove(i);
  103. for(int j = R[i];j != i;j = R[j])remove(j);
  104. Dance(d+);
  105. for(int j = L[i];j != i;j = L[j])resume(j);
  106. resume(i);
  107. }
  108. }
  109. };
  110. DLX g;
  111.  
  112. int a[][];
  113. int id[][];
  114.  
  115. int main()
  116. {
  117. //freopen("in.txt","r",stdin);
  118. //freopen("out.txt","w",stdout);
  119. int n,m;
  120. while(scanf("%d%d",&n,&m) == )
  121. {
  122. int sz = ;
  123. memset(id,,sizeof(id));
  124. for(int i = ;i < n;i++)
  125. for(int j = ;j < m;j++)
  126. {
  127. scanf("%d",&a[i][j]);
  128. if(a[i][j] == )id[i][j] = (++sz);
  129. }
  130. g.init(n*m,sz);
  131. sz = ;
  132. int n1,m1;
  133. scanf("%d%d",&n1,&m1);
  134. for(int i = ;i < n;i++)
  135. for(int j = ;j < m;j++)
  136. {
  137. for(int x = ;x < n1 && i + x < n;x++)
  138. for(int y = ;y < m1 && j + y < m;y++)
  139. if(id[i+x][j+y])
  140. g.Link(sz,id[i+x][j+y]);
  141. sz++;
  142. }
  143. g.ansd = INF;
  144. g.Dance();
  145. printf("%d\n",g.ansd);
  146. }
  147. return ;
  148. }

FZU 1686 神龙的难题 (重复覆盖)的更多相关文章

  1. FZU Problem 1686 神龙的难题 重复覆盖

    题目链接 给出大矩形的长宽, 矩形里面有1,0两个值, 给出小矩形的长宽, 求用最少的小矩形覆盖所有的1. 重复覆盖的模板题. #include <iostream> #include & ...

  2. FZU 1686 神龙的难题(DLX反复覆盖)

    FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...

  3. FZU 1686 神龙的难题 DLX反复覆盖

    DLX反复覆盖: 须要一个A*函数剪支 Problem 1686 神龙的难题 Accept: 462    Submit: 1401 Time Limit: 1000 mSec    Memory L ...

  4. [ACM] FZU 1686 神龙的难题 (DLX 反复覆盖)

    Problem 1686 神龙的难题 Accept: 444    Submit: 1365 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pro ...

  5. (简单) FZU 1686 神龙的难题 , DLX+可重复覆盖。

    Description 这是个剑与魔法的世界.英雄和魔物同在,动荡和安定并存.但总的来说,库尔特王国是个安宁的国家,人民安居乐业,魔物也比较少.但是.总有一些魔物不时会进入城市附近,干扰人民的生活.就 ...

  6. FZU 1686 神龙的难题 (DLX)

    神龙的难题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  7. FZU 1686 龙之谜 重复覆盖

    兑换0,1模型,如.注意,数据的范围 #include <stdio.h> #include <string.h> #include <iostream> #inc ...

  8. FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena

    告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...

  9. FZU1686 神龙的难题 —— Dancing Links 可重复覆盖

    题目链接:https://vjudge.net/problem/FZU-1686 Problem 1686 神龙的难题 Accept: 812    Submit: 2394 Time Limit: ...

随机推荐

  1. java @Autowired与@Resource的区别

    @Autowired与@Resource的区别     1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. 2.@Autowired默认 ...

  2. php SimpleXML 例子

    $txt = GetRemoteText($url); if(strlen($txt) > 0) { $xml = simplexml_load_string($txt); //获取xml if ...

  3. php utf-8字符转ascii字符

    function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\ ...

  4. cvs update后输出的文件标志 和 update常用的几个参数

    (1)update 和 checkout 在执行中,会为每个文件打印一行提示信息,文件的状态通过前面的单个字符指明:       U file        文件按要求从仓库得到更新.用在那些仓库里面 ...

  5. 查找SQL SERVER被锁的表和解决方法

    查找数据库中被锁表代码: select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName ...

  6. Win10光驱不见了

    1. 网上教程试了很多,如下: http://jingyan.baidu.com/article/02027811656a8b1bcd9ce570.html http://jingyan.todgo. ...

  7. c#查找string数组的某一个值的索引

    string[] array = { "A","B","C","D","H"};   var ind ...

  8. Linux:cacti环境部署

    一.监控端安装1)基础软件:安装配置cacti前,需要安装:httpd.php.mysqld.php-mysql.net-snmp.rrdtool以上均可使用yum安装:yum install -y ...

  9. leetcode 205

    205. Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are ...

  10. awk 命令

    awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各 ...