这题应该分两步来做:

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. Keil V5.1x命令“Build Target”重新编译所有文件

    网上的解决办法有多种,但不知道哪一种能对症,以下是我的解决方法:

  2. 【ASP.NET】TreeView控件学习

    相关链接 : http://www.cnblogs.com/yc-755909659/p/3596039.html

  3. 从JAVA多线程理解到集群分布式和网络设计的浅析

    对于JAVA多线程的应用非常广泛,现在的系统没有多线程几乎什么也做不了,很多时候我们在何种场合如何应用多线程成为一种首先需要选择的问题,另外关于java多线程的知识也是非常的多,本文中先介绍和说明一些 ...

  4. ITaCS Change Password web part

    http://changepassword.codeplex.com/ A webpart is used to change your sharepoint AD password.

  5. 第一个js库文件

    <!DOCTYPE html> <html xmlns=;         ;                     }                 };     })(); ...

  6. python 记录日志logging

    在项目开发中,往往要记录日志文件.用python记录日志有两种方式: 1.利用python 自带的logging库,例如: # -*- coding: utf-8 -*- import osimpor ...

  7. jquery bind()方法与live()方法的区别

    jquery bind() 方法和 live() 方法都可以绑定元素事件. <!DOCTYPE html> <html> <head> <meta chars ...

  8. tomcat集群时统计session与在线人数

    tomcat集群时,原来通过HttpSessionListener实现类监听session的创建和销毁来统计在线人数的方法不再有效,因为不是每个人登陆都会在同一个tomcat服务器上,而在另一台tom ...

  9. uva 348

    dp还是比较容易  关键是输出路径 .... #include <cstdlib> #include <cstdio> #include <cstring> #de ...

  10. 论反馈信息如何推动 IT 运维团队进步?

    我们还记得<快乐大本营>中经典游戏----快乐传真吗?游戏规则是:很多人站一排,只有第一个人才看到最准确的信息,用东西隔着,戴耳机,一一将从前一个人获得的信息传递下去,最后一个人说出推测的 ...