1565: [NOI2009]植物大战僵尸 - BZOJ
Description

Input

Output
仅包含一个整数,表示可以获得的最大能源收入。注意,你也可以选择不进行任何攻击,这样能源收入为0。
Sample Input
3 2
10 0
20 0
-10 0
-5 1 0 0
100 1 2 1
100 0
Sample Output
25
HINT
在样例中, 植物P1,1可以攻击位置(0,0), P2, 0可以攻击位置(2,1)。
一个方案为,首先进攻P1,1, P0,1,此时可以攻击P0,0 。共得到能源收益为(-5)+20+10 = 25。注意, 位置(2,1)被植物P2,0保护,所以无法攻击第2行中的任何植物。
【大致数据规模】
约20%的数据满足1 ≤ N, M ≤ 5;
约40%的数据满足1 ≤ N, M ≤ 10;
约100%的数据满足1 ≤ N ≤ 20,1 ≤ M ≤ 30,-10000 ≤ Score ≤ 10000 。
详情请见胡伯涛《最小割模型在信息学竞赛中的应用》中最大权闭合图
但是有一点不同,因为有些点不能取,所以我们首先拓扑一下,把有用的点选出来,然后再跑最小割
const
maxn=;
maxm=;
inf=;
var
d,a,first,q:array[..maxn*maxm]of longint;
next,last:array[..maxn*maxm*maxn*maxm]of longint;
map:array[..maxn*maxm,..maxn*maxm]of longint;
n,m,tot,sum,cnt:longint; function calc(i,j:longint):longint;
begin
exit(i*m+j+);
end; procedure insert(x,y:longint);
begin
inc(tot);
last[tot]:=y;
next[tot]:=first[x];
first[x]:=tot;
inc(d[y]);
end; procedure init;
var
i,j,k,l,r,x,y:longint;
begin
read(n,m);
for i:= to n- do
for j:= to m- do
begin
read(a[calc(i,j)]);
read(k);
if j> then insert(calc(i,j),calc(i,j-));
for l:= to k do
begin
read(x,y);
insert(calc(i,j),calc(x,y));
end;
end;
l:=;r:=;
for i:= to n -1do
if d[calc(i,m-)]= then
begin
inc(r);
q[r]:=calc(i,m-);
end;
while l<=r do
begin
if a[q[l]]> then inc(sum,a[q[l]]);
if a[q[l]]> then inc(map[,q[l]],a[q[l]]);
if a[q[l]]< then inc(map[q[l],n*m+],-a[q[l]]);
i:=first[q[l]];
while i<> do
begin
dec(d[last[i]]);inc(map[last[i],q[l]],inf);
if d[last[i]]= then
begin
inc(r);
q[r]:=last[i];
end;
i:=next[i];
end;
inc(l);
end;
cnt:=r;
end; var
dis,vh,his,pre:array[..maxn*maxm]of longint;
flow:longint; procedure sap;
var
i,j,aug,min:longint;
flag:boolean;
begin
vh[]:=cnt+;
i:=;aug:=inf;
while dis[i]<n*m+ do
begin
his[i]:=aug;
flag:=false;
for j:= to n*m+ do
if (map[i,j]>) and (dis[i]=dis[j]+) then
begin
flag:=true;
if aug>map[i,j] then aug:=map[i,j];
pre[j]:=i;
i:=j;
if i=n*m+ then
begin
inc(flow,aug);
while i<> do
begin
inc(map[i,pre[i]],aug);
dec(map[pre[i],i],aug);
i:=pre[i];
end;
aug:=inf;
end;
break;
end;
if flag then continue;
min:=n*m+;
for j:= to n*m+ do
if (map[i,j]>) and (dis[j]<min) then min:=dis[j];
dec(vh[dis[i]]);
if vh[dis[i]]= then break;
dis[i]:=min+;
inc(vh[min+]);
if i<> then
begin
i:=pre[i];
aug:=his[i];
end;
end;
writeln(sum-flow);
end; begin
init;
sap;
end.
1565: [NOI2009]植物大战僵尸 - BZOJ的更多相关文章
- bzoj 1565 [NOI2009]植物大战僵尸 解题报告
1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2161 Solved: 1000[Submit][Stat ...
- BZOJ 1565: [NOI2009]植物大战僵尸( 最小割 )
先拓扑排序搞出合法的, 然后就是最大权闭合图模型了.... --------------------------------------------------------------------- ...
- Bzoj 1565: [NOI2009]植物大战僵尸 最大权闭合图,拓扑排序
题目: http://cojs.tk/cogs/problem/problem.php?pid=410 410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:p ...
- BZOJ 1565 [NOI2009]植物大战僵尸 | 网络流
传送门 BZOJ 1565 题解 这道题也是个经典的最大权闭合子图-- 复习一下最大权闭合子图是什么? 就是一个DAG上,每个点有个或正或负的点权,有的点依赖于另外一些点(如果选这个点,则被依赖点必选 ...
- BZOJ 1565 NOI2009 植物大战僵尸 topo+最小割(最大权闭合子图)
题目链接:https://www.luogu.org/problemnew/show/P2805(bzoj那个实在是有点小小的辣眼睛...我就把洛谷的丢出来吧...) 题意概述:给出一张有向图,这张有 ...
- bzoj 1565 [NOI2009]植物大战僵尸【tarjan+最大权闭合子图】
一上来以为是裸的最大权闭合子图,上来就dinic -然后没过样例.不得不说样例还是非常良心的给了一个强连通分量,要不然就WA的生活不能自理了 然后注意到有一种特殊情况:每个植物向他保护的植物连边(包括 ...
- BZOJ 1565: [NOI2009]植物大战僵尸(网络流+缩点)
传送门 解题思路 最大权闭合子图.但是要注意一些细节,假如有一堆植物形成一个环,那么这些植物都是无敌的,并且他们保护的植物是无敌的,他们保护的保护的植物是无敌 的.所以要缩点,然后拓扑排序一次判无敌, ...
- bzoj1565: [NOI2009]植物大战僵尸 最大权闭合子图,tarjan
bzoj1565: [NOI2009]植物大战僵尸 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1565 思路 很容易的想到最大权闭合子图 ...
- b2OJ_1565_[NOI2009]植物大战僵尸_拓扑排序+最大权闭合子图
b2OJ_1565_[NOI2009]植物大战僵尸_拓扑排序+最大权闭合子 题意:n*m个植物,每个植物有分数(可正可负),和能保护植物的位置.只能从右往左吃,并且不能吃正被保护着的,可以一个不吃,求 ...
随机推荐
- css3 2d
CSS3 2D 转换 通过 CSS3 转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. 以下是 2D 转换 1 translate()通过 translate() 方法,元素从其当前位置移动 ...
- FileUpload无法赋值解决方案
FileUpload无法赋值解决方案 编写人:CC阿爸 2015-1-27 今天在这里,我想与大家一起分享如何处理fileupload控件不能赋值的问题.有兴趣的同学,可以一同探讨与学习一下,否则就略 ...
- Silverlight取得Session
首先Session是运行在服务器上的,而Silverlight运行在客户端.因此在Silverlight中使用SESSION的说法并不准确, 只因大家经常这样搜索才起这个名字. 有两种方法实现Silv ...
- javascript中match和RegExp组合用法
function getCookie(name)//取cookies函数 { //coook中document.cookie = "age=12; name=1.css"; var ...
- UITableView去除空白cell上多余separator
具体的效果可以参考微信ios7版的UITableview 它最后一行cell的separator是顶到最左边的 首先设置tableFooterView _messageTableview.tableF ...
- 从PC跳转至wap
<script language="JavaScript">function mobile_device_detect(url){var thisOS=navigato ...
- 关于js中立即执行的匿名函数写法
/*最流行的写法*/ (function() { alert("run!") })(); /* !号可以有1~正无穷个,所以这一种就可以衍生无数种方式 */ !!!(functio ...
- 第五节:AppDomain FirstChance异常通知
每个AppDomain都可关联一组回调方法:CLR开始查找AppDomain中的catch块时,这些回调方法就会得到调用.这些方法可执行日志记录操作.除此之外,宿主可利用这个机制监视AppDomain ...
- 几道华为经典C语言面试题
1.找错 void test1() { char string[10]; char* str1="0123456789"; strcpy(string, str1); } 这里st ...
- Requests:Python HTTP Module学习笔记(二)(转)
在上一篇日志中对Requests做了一个整体的介绍,接来下再介绍一些高级的用法,主要资料还是翻译自官网的文档,如有错漏,欢迎指正. 参考资料:http://docs.python-requests.o ...