这题应该分两步来做:

1、拓扑排序,去掉无敌点

2、求最大闭合子图

需要注意几点:

1、拓扑排序时,如果(i,j)可以攻击到(x,y),那么增加(x,y)的入度,而不是(i,j)的入度

因为入度代表着要攻击它需要事先攻击几个点

2、求最大闭合子图时,用所有的正权点-最大流

3、求最大闭合子图时,如果(i,j)可以攻击到(x,y),那么连一条边(x,y)到(i,j),容量为正无穷

因为在最大闭合子图中边(x,y)到(i,j)意味着选(x,y)就必须要选(i,j),这与实际含义相符

4、s到正权点,容量为正权点的点权

负权点到t,容量为负权点的点权的绝对值

5、要做好对数据规模的估计

代码:

  1. type node=record
  2. go,next,c:longint;
  3. end;
  4. var e:array[..] of node;
  5. head,tail,i,n,m,j,tot,max,ans,s,t,x,y:longint;
  6. w,cur,first,inp,q,h:array[..] of longint;
  7. can:array[..] of boolean;
  8. a:array[..,..] of longint;
  9. procedure insert(x,y,z:longint);
  10. begin
  11. inc(tot);
  12. e[tot].go:=y;
  13. e[tot].c:=z;
  14. e[tot].next:=first[x];
  15. first[x]:=tot;
  16. inc(tot);
  17. e[tot].go:=x;
  18. e[tot].c:=;
  19. e[tot].next:=first[y];
  20. first[y]:=tot;
  21. end;
  22. function min(x,y:longint):longint;
  23. begin
  24. if x<y then exit(x) else exit(y);
  25. end;
  26. procedure init;
  27. begin
  28. readln(n,m);
  29. fillchar(inp,sizeof(inp),);
  30. for i:= to n*m do
  31. begin
  32. read(w[i]);read(a[i,]);
  33. for j:= to a[i,] do
  34. begin
  35. read(x,y);inc(x);inc(y);
  36. a[i,j]:=(x-)*m+y;
  37. inc(inp[(x-)*m+y]);
  38. end;
  39. if i mod m<> then
  40. begin
  41. inc(a[i,]);a[i,a[i,]]:=i-;inc(inp[i-]);
  42. end;
  43. readln;
  44. end;
  45. end;
  46. procedure topsort;
  47. begin
  48. head:=;tail:=;
  49. fillchar(q,sizeof(q),);
  50. fillchar(can,sizeof(can),false);
  51. for i:= to n*m do
  52. if inp[i]= then
  53. begin
  54. can[i]:=true;inc(tail);q[tail]:=i;
  55. end;
  56. while head<tail do
  57. begin
  58. inc(head);
  59. x:=q[head];
  60. for i:= to a[x,] do
  61. begin
  62. y:=a[x,i];
  63. dec(inp[y]);
  64. if inp[y]= then
  65. begin
  66. can[y]:=true;
  67. inc(tail);
  68. q[tail]:=y;
  69. end;
  70. end;
  71. end;
  72. end;
  73. procedure makegraph;
  74. begin
  75. max:=;
  76. for i:= to n*m do
  77. if can[i] then
  78. begin
  79. if w[i]> then inc(max,w[i]);
  80. for j:= to a[i,] do
  81. begin
  82. y:=a[i,j];
  83. if can[y] then insert(y,i,maxlongint>>);
  84. end;
  85. if w[i]> then insert(s,i,w[i])
  86. else insert(i,t,-w[i]);
  87. end;
  88. end;
  89. function bfs:boolean;
  90. var i,x,y:longint;
  91. begin
  92. fillchar(h,sizeof(h),);
  93. fillchar(q,sizeof(q),);
  94. head:=;tail:=;q[]:=s;h[s]:=;
  95. while head<tail do
  96. begin
  97. inc(head);
  98. x:=q[head];
  99. i:=first[x];
  100. while i<> do
  101. begin
  102. y:=e[i].go;
  103. if (h[y]=) and (e[i].c<>) then
  104. begin
  105. h[y]:=h[x]+;
  106. inc(tail);
  107. q[tail]:=y;
  108. end;
  109. i:=e[i].next;
  110. end;
  111. end;
  112. exit(h[t]<>);
  113. end;
  114. function dfs(x,f:longint):longint;
  115. var i,y,tmp,used:longint;
  116. begin
  117. if (x=t) or (f=) then exit(f);
  118. i:=cur[x];tmp:=;used:=;
  119. while i<> do
  120. begin
  121. y:=e[i].go;
  122. if (h[y]=h[x]+) and (e[i].c<>) then
  123. begin
  124. tmp:=dfs(y,min(e[i].c,f-used));
  125. dec(e[i].c,tmp);
  126. inc(e[i xor ].c,tmp);
  127. if e[i].c<> then cur[x]:=i;
  128. inc(used,tmp);
  129. if used=f then exit(f);
  130. end;
  131. i:=e[i].next;
  132. end;
  133. if used= then h[x]:=-;
  134. exit(used);
  135. end;
  136.  
  137. procedure dinic;
  138. begin
  139. while bfs do
  140. begin
  141. for i:= to n*m+ do cur[i]:=first[i];
  142. inc(ans,dfs(s,maxlongint>>));
  143. end;
  144. end;
  145.  
  146. procedure main;
  147. begin
  148. tot:=;
  149. s:=;t:=n*m+;
  150. topsort;
  151. makegraph;
  152. dinic;
  153. writeln(max-ans);
  154. end;
  155. begin
  156. init;
  157. main;
  158. end.

NOI2009植物大战僵尸的更多相关文章

  1. 图论(网络流):COGS 410. [NOI2009] 植物大战僵尸

    410. [NOI2009] 植物大战僵尸 ★★★   输入文件:pvz.in   输出文件:pvz.out   简单对比时间限制:2 s   内存限制:512 MB [问题描述] Plants vs ...

  2. P2805 [NOI2009]植物大战僵尸

    题目地址:P2805 [NOI2009]植物大战僵尸 最大权闭合子图 若有向图 \(G\) 的子图 \(V\) 满足: \(V\) 中顶点的所有出边均指向 \(V\) 内部的顶点,则称 \(V\) 是 ...

  3. COGS410. [NOI2009] 植物大战僵尸

    410. [NOI2009] 植物大战僵尸 ★★★   输入文件:pvz.in   输出文件:pvz.out   简单对比时间限制:2 s   内存限制:512 MB [问题描述] Plants vs ...

  4. BZOJ 1565: [NOI2009]植物大战僵尸

    1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2317  Solved: 1071[Submit][Stat ...

  5. 【刷题】BZOJ 1565 [NOI2009]植物大战僵尸

    Description Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻. ...

  6. 【bzoj1565】[NOI2009]植物大战僵尸

    1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2164  Solved: 1001[Submit][Stat ...

  7. 【最大权闭合子图 tarjan】bzoj1565: [NOI2009]植物大战僵尸

    dinic+tarjan板子练手题 Description Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其 中P ...

  8. BZOJ1565: [NOI2009]植物大战僵尸

    Description Input Output 仅包含一个整数,表示可以获得的最大能源收入.注意,你也可以选择不进行任何攻击,这样能源收入为0. Sample Input 3 2 10 0 20 0 ...

  9. 【bzoj1565】 NOI2009—植物大战僵尸

    http://www.lydsy.com/JudgeOnline/problem.php?id=1565 (题目链接) 题意 给出$n*m$的棋盘,僵尸攻击每个格子可以获得$v$的分数,每个格子又会保 ...

  10. luogu2805 [NOI2009]植物大战僵尸

    想象一下,要搞掉一个植物,必须先搞掉另一些植物--我们可以发现这是一个最大权闭合子图的问题. 最大权闭合子图的话,太空飞行计划问题是一个入门题,可以一看. 然而我们手玩一下样例就会惊恐地发现,保护关系 ...

随机推荐

  1. 处理部分WordPress核心代码或功能,让你的网站更快

    处理部分WordPress核心代码或功能,让你的网站更快 http://www.wpdaxue.com/speed-up-wordpress.html

  2. Spark Streaming揭秘 Day34 解析UI监听模式

    Spark Streaming揭秘 Day34 解析UI监听模式 今天分享下SparkStreaming中的UI部分,和所有的UI系统一样,SparkStreaming中的UI系统使用的是监听器模式. ...

  3. HDFS知识体系 思维导图

  4. css 面试学习

    最经在学习前端的一些东西 转载于http://www.cnblogs.com/lei2007/archive/2013/08/16/3262897.html 雅虎的css前端的35条定律

  5. Oracle回收站

    回收站是删除对象使用的存储空间.可以使用实例参数recyclebin禁用回收站,默认是on,可以为某个会话或系统设置为off或on.所有模式都有一个回收站. 当表空间不足时可以自动重用回收站对象占用的 ...

  6. Delaunay三角剖分

    Bowyer-Watson算法:1.假设已经生成了连接若干个顶点的Delaunay三角网格:2.加入一个新的节点,找出所有外接圆包含新加入节点的三角形,并将这些三角形删除形成一个空洞:3.空洞的节点与 ...

  7. [转]控制反转(IOC)和依赖注入(DI)

    http://blog.csdn.net/Elite_1989/article/details/16851565 控制反转和依赖注入可以理解成同一个东西,都是为解耦而生的~ 控制反转(IoC=Inve ...

  8. 1042: [HAOI2008]硬币购物 - BZOJ

    Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法.Input 第一行 ...

  9. [machine learning] Loss Function view

    [machine learning] Loss Function view 有关Loss Function(LF),只想说,终于写了 一.Loss Function 什么是Loss Function? ...

  10. spoj 1436

    用并查集看一下是否会围成一个环  若围成环直接输出NO   当然 当 m >= n  时必然会围成环直接输出NO #include <algorithm> #include < ...