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的更多相关文章

  1. bzoj 1565 [NOI2009]植物大战僵尸 解题报告

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

  2. BZOJ 1565: [NOI2009]植物大战僵尸( 最小割 )

    先拓扑排序搞出合法的, 然后就是最大权闭合图模型了.... --------------------------------------------------------------------- ...

  3. Bzoj 1565: [NOI2009]植物大战僵尸 最大权闭合图,拓扑排序

    题目: http://cojs.tk/cogs/problem/problem.php?pid=410 410. [NOI2009] 植物大战僵尸 ★★★   输入文件:pvz.in   输出文件:p ...

  4. BZOJ 1565 [NOI2009]植物大战僵尸 | 网络流

    传送门 BZOJ 1565 题解 这道题也是个经典的最大权闭合子图-- 复习一下最大权闭合子图是什么? 就是一个DAG上,每个点有个或正或负的点权,有的点依赖于另外一些点(如果选这个点,则被依赖点必选 ...

  5. BZOJ 1565 NOI2009 植物大战僵尸 topo+最小割(最大权闭合子图)

    题目链接:https://www.luogu.org/problemnew/show/P2805(bzoj那个实在是有点小小的辣眼睛...我就把洛谷的丢出来吧...) 题意概述:给出一张有向图,这张有 ...

  6. bzoj 1565 [NOI2009]植物大战僵尸【tarjan+最大权闭合子图】

    一上来以为是裸的最大权闭合子图,上来就dinic -然后没过样例.不得不说样例还是非常良心的给了一个强连通分量,要不然就WA的生活不能自理了 然后注意到有一种特殊情况:每个植物向他保护的植物连边(包括 ...

  7. BZOJ 1565: [NOI2009]植物大战僵尸(网络流+缩点)

    传送门 解题思路 最大权闭合子图.但是要注意一些细节,假如有一堆植物形成一个环,那么这些植物都是无敌的,并且他们保护的植物是无敌的,他们保护的保护的植物是无敌 的.所以要缩点,然后拓扑排序一次判无敌, ...

  8. bzoj1565: [NOI2009]植物大战僵尸 最大权闭合子图,tarjan

    bzoj1565: [NOI2009]植物大战僵尸 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1565 思路 很容易的想到最大权闭合子图 ...

  9. b2OJ_1565_[NOI2009]植物大战僵尸_拓扑排序+最大权闭合子图

    b2OJ_1565_[NOI2009]植物大战僵尸_拓扑排序+最大权闭合子 题意:n*m个植物,每个植物有分数(可正可负),和能保护植物的位置.只能从右往左吃,并且不能吃正被保护着的,可以一个不吃,求 ...

随机推荐

  1. dataGridView 如何默认选中第一行

    datagridview默认选中第一行方法: this.dataGridView1.Rows[0].Selected = true; datagridview 去除 默认选中第一行方法:在绑定data ...

  2. [leetcode]_Best Time to Buy and Sell Stock I && II

    一个系列三道题,我都不会做,google之答案.过了两道,第三道看不懂,放置,稍后继续. 一.Best Time to Buy and Sell Stock I 题目:一个数组表示一支股票的价格变换. ...

  3. c语言学习的第10天

    #include <stdio.h> int main() { int many; printf("你想看几次?"); scanf("%d",&am ...

  4. 利用java读写Excel文件

    一.读取Excel文件内容 java 代码 public static String readExcel(File file){ StringBuffer sb = new StringBuffer( ...

  5. php实现显示网站运行时间-秒转换年月日时分秒

    <?php // 设置时区 date_default_timezone_set('Asia/Shanghai'); /** * 秒转时间,格式 年 月 日 时 分 秒 * * @author w ...

  6. Java排序

    给出10个数,使用某种排序方法,按照从小到大的顺序输出个个数. 根据要求,首先得给出这10个数,这里的算法需要一个循环,数据结构需要一个长度为10的整型数组.首先用BufferedReader in= ...

  7. C# 平时碰见的问题【6】

    EF Code First 设置复合主键的方法 除了单纯多对多的关系表外, 我们可能在关系表上加其他的属性: 比如[订单行] 对应的[订单]和[商品]就需要多一个数量字段 而又不想在这个[订单行]表上 ...

  8. SqlBulkCopy 插入100W条数据时 属性BatchSize的作用

    (1)100W条insert语句在一个连接内一句一句加 花了01:17:19.0542805 (2) SqlBulkCopy 插入100W条数据 设置BatchSize=500 耗时:00:03:29 ...

  9. Linux之kernal分析与启动20160610

    说一下LINUX内核的分析与启动: 一. 内核启动流程,据此配置内核(机器ID) 1.1 修改Makefile 1.2 选择默认配置 : make s3c2410_defconfig 1.3 make ...

  10. highcharts 显示点值的效果

    plotOptions: { line: { /* <s:if test='#request.rdflags=="point"'> <s:if test=&quo ...