这题应该分两步来做:

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、要做好对数据规模的估计

代码:

 type node=record
go,next,c:longint;
end;
var e:array[..] of node;
head,tail,i,n,m,j,tot,max,ans,s,t,x,y:longint;
w,cur,first,inp,q,h:array[..] of longint;
can:array[..] of boolean;
a:array[..,..] of longint;
procedure insert(x,y,z:longint);
begin
inc(tot);
e[tot].go:=y;
e[tot].c:=z;
e[tot].next:=first[x];
first[x]:=tot;
inc(tot);
e[tot].go:=x;
e[tot].c:=;
e[tot].next:=first[y];
first[y]:=tot;
end;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
procedure init;
begin
readln(n,m);
fillchar(inp,sizeof(inp),);
for i:= to n*m do
begin
read(w[i]);read(a[i,]);
for j:= to a[i,] do
begin
read(x,y);inc(x);inc(y);
a[i,j]:=(x-)*m+y;
inc(inp[(x-)*m+y]);
end;
if i mod m<> then
begin
inc(a[i,]);a[i,a[i,]]:=i-;inc(inp[i-]);
end;
readln;
end;
end;
procedure topsort;
begin
head:=;tail:=;
fillchar(q,sizeof(q),);
fillchar(can,sizeof(can),false);
for i:= to n*m do
if inp[i]= then
begin
can[i]:=true;inc(tail);q[tail]:=i;
end;
while head<tail do
begin
inc(head);
x:=q[head];
for i:= to a[x,] do
begin
y:=a[x,i];
dec(inp[y]);
if inp[y]= then
begin
can[y]:=true;
inc(tail);
q[tail]:=y;
end;
end;
end;
end;
procedure makegraph;
begin
max:=;
for i:= to n*m do
if can[i] then
begin
if w[i]> then inc(max,w[i]);
for j:= to a[i,] do
begin
y:=a[i,j];
if can[y] then insert(y,i,maxlongint>>);
end;
if w[i]> then insert(s,i,w[i])
else insert(i,t,-w[i]);
end;
end;
function bfs:boolean;
var i,x,y:longint;
begin
fillchar(h,sizeof(h),);
fillchar(q,sizeof(q),);
head:=;tail:=;q[]:=s;h[s]:=;
while head<tail do
begin
inc(head);
x:=q[head];
i:=first[x];
while i<> do
begin
y:=e[i].go;
if (h[y]=) and (e[i].c<>) then
begin
h[y]:=h[x]+;
inc(tail);
q[tail]:=y;
end;
i:=e[i].next;
end;
end;
exit(h[t]<>);
end;
function dfs(x,f:longint):longint;
var i,y,tmp,used:longint;
begin
if (x=t) or (f=) then exit(f);
i:=cur[x];tmp:=;used:=;
while i<> do
begin
y:=e[i].go;
if (h[y]=h[x]+) and (e[i].c<>) then
begin
tmp:=dfs(y,min(e[i].c,f-used));
dec(e[i].c,tmp);
inc(e[i xor ].c,tmp);
if e[i].c<> then cur[x]:=i;
inc(used,tmp);
if used=f then exit(f);
end;
i:=e[i].next;
end;
if used= then h[x]:=-;
exit(used);
end; procedure dinic;
begin
while bfs do
begin
for i:= to n*m+ do cur[i]:=first[i];
inc(ans,dfs(s,maxlongint>>));
end;
end; procedure main;
begin
tot:=;
s:=;t:=n*m+;
topsort;
makegraph;
dinic;
writeln(max-ans);
end;
begin
init;
main;
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. DB2分区表删除和添加分区

    1.数据库版本 2.具体procedure DROP PROCEDURE DB2USER.TOOLS_PARTITION_TABLE_SHOW (VARCHAR ()); )) /********** ...

  2. Cent os关机与重启命令详解

    Cent OS关机与重启命令详解 分类: Linux2012-10-02 14:06 5553人阅读 评论(0) 收藏 举报 centoslinuxsignallogin工作windows Linux ...

  3. 选中excel中的对象

    2007在查找和选择中点击“选择对象”,然后再全选全个sheet(ctrl+a)就可以看到了. 2010 “选择对象”在  开始——查找和选择——选择对象

  4. linux tail

    tail 命令从指定点开始将文件写到标准输出,使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  5. Qt编译postgreSQL驱动

    安装postgreSQL,安装目录下的lib和bin添加到path 打开Qt安装目录,找到src\plugins\sqldrivers\psql编辑psql.pro,添加INCLUDEPATH += ...

  6. iOS定位坐标转换工具-b

    坐标系介绍 首先介绍一下目前的定位坐标系统1.地球坐标 :( 代号:GPS.WGS84 )--- 有W就是世界通用的也就是原始坐标体系,这是国际公认的世界标准坐标体系: 使用 WGS84 坐标系统的产 ...

  7. (转)深入理解SP、LR和PC

    网址:http://blog.csdn.net/zhou1232006/article/details/6149548 深入理解ARM的这三个寄存器,对编程以及操作系统的移植都有很大的裨益. 1.堆栈 ...

  8. 使用Yeoman搭建 AngularJS 应用 (8) —— 让我们搭建一个网页应用

    原文地址:http://yeoman.io/codelab/write-app.html 创建一个新的模板来显示一个todo的列表 打开views/main.html 为了从一个干净的模板开始,删除m ...

  9. wget 下载百度云jdk

    oracle官网下载需要登录下载 所以从百度云下载 wget -c -O "URL"

  10. 基于注解风格的Spring-MVC的拦截器

    基于注解风格的Spring-MVC的拦截器 Spring-MVC如何使用拦截器,官方文档只给出了非注解风格的例子.那么基于注解风格如何使用拦截器呢? 基于注解基本上有2个可使用的定义类,分别是Defa ...