2333333333333333333333333333333333333333333333

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

辣鸡出题人辣鸡出题人辣鸡出题人辣鸡出题人辣鸡出题人辣鸡出题人

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<queue>
  5. #include<algorithm>
  6. #define inf 1000000007
  7. using namespace std;
  8. int n,m,t,wh[][],dis[][],x[],y[],tab[][][][],pre[][],fro[][][][],f[(<<)+][][];
  9. int dx[]={,-,,,},dy[]={,,,,-};
  10. bool map[][],vis[][];
  11. char s[];
  12. queue <int> q;
  13. void reset()
  14. {
  15. for (int i=;i<=n;i++)
  16. for (int j=;j<=m;j++)
  17. dis[i][j]=inf;
  18. while (!q.empty()) q.pop();
  19. memset(vis,false,sizeof(vis));
  20. }
  21. bool judge(int x,int y)
  22. {
  23. if ((x>=) && (x<=n) && (y>=) && (y<=m) && (!map[x][y]))
  24. return true;
  25. return false;
  26. }
  27. void spfa(int pos,int dir)
  28. {
  29. memset(pre,,sizeof(pre));
  30. if (!judge(x[pos]+dx[dir],y[pos]+dy[dir])) return;
  31. dis[x[pos]+dx[dir]][y[pos]+dy[dir]]=;vis[x[pos]+dx[dir]][y[pos]+dy[dir]]=true;
  32. q.push(x[pos]+dx[dir]);q.push(y[pos]+dy[dir]);
  33. while (!q.empty())
  34. {
  35. int hx,hy;
  36. hx=q.front();q.pop();hy=q.front();q.pop();
  37. int p=;
  38. while (judge(hx-p,hy))
  39. {
  40. if ((dis[hx-p][hy]>dis[hx][hy]+) || ((dis[hx-p][hy]==dis[hx][hy]+) && (wh[hx-p][hy]==)))
  41. {
  42. dis[hx-p][hy]=dis[hx][hy]+;
  43. pre[hx-p][hy]=;
  44. if (!vis[hx-p][hy])
  45. {
  46. vis[hx-p][hy]=true;
  47. q.push(hx-p);q.push(hy);
  48. }
  49. }
  50. p++;
  51. }
  52. p=;
  53. while (judge(hx+p,hy))
  54. {
  55. if ((dis[hx+p][hy]>dis[hx][hy]+) || ((dis[hx+p][hy]==dis[hx][hy]+) && (wh[hx+p][hy]==)))
  56. {
  57. dis[hx+p][hy]=dis[hx][hy]+;
  58. pre[hx+p][hy]=;
  59. if (!vis[hx+p][hy])
  60. {
  61. vis[hx+p][hy]=true;
  62. q.push(hx+p);q.push(hy);
  63. }
  64. }
  65. p++;
  66. }
  67. p=;
  68. while (judge(hx,hy-p))
  69. {
  70. if ((dis[hx][hy-p]>dis[hx][hy]+) || ((dis[hx][hy-p]==dis[hx][hy]+) && (wh[hx][hy-p]==)))
  71. {
  72. dis[hx][hy-p]=dis[hx][hy]+;
  73. pre[hx][hy-p]=;
  74. if (!vis[hx][hy-p])
  75. {
  76. vis[hx][hy-p]=true;
  77. q.push(hx);q.push(hy-p);
  78. }
  79. }
  80. p++;
  81. }
  82. p=;
  83. while (judge(hx,hy+p))
  84. {
  85. if ((dis[hx][hy+p]>dis[hx][hy]+) || ((dis[hx][hy+p]==dis[hx][hy]+) && (wh[hx][hy+p]==)))
  86. {
  87. dis[hx][hy+p]=dis[hx][hy]+;
  88. pre[hx][hy+p]=;
  89. if (!vis[hx][hy+p])
  90. {
  91. vis[hx][hy+p]=true;
  92. q.push(hx);q.push(hy+p);
  93. }
  94. }
  95. p++;
  96. }
  97. vis[hx][hy]=false;
  98. }
  99. }
  100. void get_tab(int pos,int dir)
  101. {
  102. for (int i=;i<=t+;i++)
  103. for (int j=;j<=;j++)
  104. {
  105. if (judge(x[i]+dx[j],y[i]+dy[j]))
  106. {
  107. tab[pos][dir][i][j]=dis[x[i]+dx[j]][y[i]+dy[j]];
  108. fro[pos][dir][i][j]=pre[x[i]+dx[j]][y[i]+dy[j]];
  109. }
  110. }
  111. }
  112. int main()
  113. {
  114. //freopen("secret.in","r",stdin);
  115. //freopen("secret.out","w",stdout);
  116. memset(map,false,sizeof(map));
  117. scanf("%d%d%d",&n,&m,&t);
  118. for (int i=;i<=n;i++)
  119. {
  120. scanf("\n%s",s);
  121. for (int j=;j<m;j++)
  122. if (s[j]=='#') map[i][j+]=true;
  123. }
  124. for (int i=;i<=t;i++)
  125. {
  126. scanf("%d%d",&x[i],&y[i]);
  127. map[x[i]][y[i]]=true;
  128. }
  129. for (int i=;i<=t;i++)
  130. {
  131. for (int j=;j<=;j++)
  132. {
  133. if (judge(x[i]+dx[j],y[i]+dy[j]))
  134. wh[x[i]+dx[j]][y[i]+dy[j]]=j;
  135. }
  136. }
  137. scanf("%d%d",&x[t+],&y[t+]);
  138. for (int i=;i<=t+;i++)
  139. for (int j=;j<=;j++)
  140. for (int k=;k<=t;k++)
  141. for (int l=;l<=;l++)
  142. tab[i][j][k][l]=inf;
  143. for (int i=;i<=t;i++)
  144. {
  145. for (int j=;j<=;j++)
  146. {
  147. reset();
  148. spfa(i,j);
  149. get_tab(i,j);
  150. }
  151. }
  152. reset();
  153. spfa(t+,);
  154. for (int i=;i<=t+;i++)
  155. for (int j=;j<=;j++)
  156. {
  157. if (judge(x[i]+dx[j],y[i]+dy[j]))
  158. {
  159. tab[t+][][i][j]=dis[x[i]+dx[j]][y[i]+dy[j]];
  160. fro[t+][][i][j]=pre[x[i]+dx[j]][y[i]+dy[j]];
  161. }
  162. }
  163. int top=(<<t)-;
  164. for (int s=;s<=top;s++)
  165. for (int i=;i<=t;i++)
  166. for (int j=;j<=;j++)
  167. f[s][i][j]=inf;
  168. for (int i=;i<=t;i++)
  169. for (int j=;j<=;j++)
  170. {
  171. if (fro[t+][][i][j]!=j)
  172. f[<<(i-)][i][j]=tab[t+][][i][j]+;
  173. else f[<<(i-)][i][j]=tab[t+][][i][j];
  174. }
  175. for (int ss=;ss<=top;ss++)
  176. {
  177. for (int i=;i<=t;i++)
  178. {
  179. if (ss&(<<(i-)))
  180. {
  181. for (int j=;j<=t;j++)
  182. {
  183. if (ss&(<<(j-))) continue;
  184. for (int k=;k<=;k++)
  185. for (int l=;l<=;l++)
  186. {
  187. if (tab[i][k][j][l]==inf) continue;
  188. if (fro[i][k][j][l]!=l)
  189. f[ss|<<(j-)][j][l]=min(f[ss|<<(j-)][j][l],f[ss][i][k]+tab[i][k][j][l]+);
  190. else f[ss|<<(j-)][j][l]=min(f[ss|<<(j-)][j][l],f[ss][i][k]+tab[i][k][j][l]);
  191. }
  192. }
  193. }
  194. }
  195. }
  196. int ans=inf;
  197. for (int i=;i<=t;i++)
  198. for (int j=;j<=;j++)
  199. ans=min(ans,f[top][i][j]);
  200. printf("%d\n",ans);
  201. return ;
  202. }

BZOJ 1556 墓地秘密的更多相关文章

  1. bzoj 1556 墓地秘密 —— 状压DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1556 预处理出两个障碍四个方向之间的距离(转弯次数),就可以状压DP了: 但预处理很麻烦.. ...

  2. bzoj 1556: 墓地秘密【状压dp+spfa】

    显然是状压,显然不可能把所有格子压起来 仔细观察发现只有机关周围的四个格子有用以及起点,所以我们用spfa处理出这些格子两两之间的距离(注意细节--这里写挂了好几次),然后设f[s][i]为碰完的机关 ...

  3. BZOJ1556 墓地秘密

    题意 费尽周折,终于将众将士的残骸运送到了KD军事基地地底层的大型墓地入口.KD的伙伴和战友们都参加了这次重大的送葬仪式.右边是一扇敞开的大门,进去便是墓地了,左边是一堵凹进去的墙,没有什么特别的地方 ...

  4. 洛谷 2922 BZOJ 1590 [USACO08DEC]秘密消息Secret Message

    [题意概述] 给出n个01串组成的字典和m个询问,每次询问某个01串和多少个字典中的串有相同的前缀.(前缀长度是两串中较小的部分) [题解] 直接上Trie树即可.树上每个节点记录两个信息:这个节点有 ...

  5. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  6. BZOJ 刷题总结(持续更新)

    本篇博客按照题号排序(带*为推荐题目) 1008 [HNOI2008]越狱 很经典的题了..龟速乘,龟速幂裸题,, 1010 [HNOI2008]玩具装箱toy* 斜率优化 基本算是裸题. 1012 ...

  7. bzoj1556 (DP)

    bzoj 1556 点这里打开题目 题目是求 a^2 求和: 原问题可以转化为:两个人在玩这个东西,问这两个人弄出来的序列相同的有多少种情况,操作方式不同即为一种不同的情况. 就这个问题,参考大佬的D ...

  8. bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息

    1590: [Usaco2008 Dec]Secret Message 秘密信息 Description     贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息.     信息是二进制的,共 ...

  9. 【BZOJ】1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1643 这题和完全背包十分相似, 但是不能用1维做........原因貌似是不能确定块数(还是有0的面 ...

随机推荐

  1. GridControl Find/Clear 添加图标

    public static void ControlFind(GridControl grid) { FindControl fControl = null; foreach (Control ite ...

  2. ExtJS之Ext.getDom

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  3. arcgis地图操作的资料URL,以供以后查阅

    更改Arcgis Web应用程序的端口号8399: http://help.arcgis.com/zh-cn/arcgisserver/10.0/help/arcgis_server_java_hel ...

  4. 23种设计模式学习一(单列模式)singleton

    单列模式的类(单线程下的) class Singleton { private static Singleton instance; private Singleton() { } public st ...

  5. 【uva753/poj1087/hdu1526-A Plug for UNIX】最大流

    题意:给定n个插座,m个插头,k个转换器(x,y),转换器可以让插头x转成插头y.问最少有多少个插头被剩下. 题解: 最大流或者二分图匹配.然而我不知道怎么打二分图匹配..打了最大流.这题字符串比较坑 ...

  6. JavaWeb项目开发案例精粹-第6章报价管理系统-04Service层

    1. package com.sanqing.service; import com.sanqing.dao.DAO; import com.sanqing.po.Customer; /** * 客户 ...

  7. 扩展 delphi 泛型 以实现类似lambda功能 , C#中的any count first last 等扩展方法

    扩展 delphi 泛型 以实现类似lambda功能 , C#中的any count first last 等扩展方法 在C#中对泛型的扩展,输入参数是泛型本身的内容,返回值则是bool.基于这一点, ...

  8. USACO Section 3.1: Agri-Net

    minimal spanning tree的经典题 /* ID: yingzho1 LANG: C++ TASK: agrinet */ #include <iostream> #incl ...

  9. jenkins的搭建和使用

    Jenkins 是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从繁杂的集成中解脱出来,专注于更为重要的业务逻辑实现上.同时 Jenkins 能实施监控集成中存在的错误,提供详细的日志文件和 ...

  10. 由反汇编C程序来理解计算机是如何工作的

    C语言代码 int g(int x) { return x + 109; } int f(int x) { return g(x); } int main() { return f(122) + 3; ...