bzoj 2039 最小割模型
比较明显的网络流最小割模型,对于这种模型我们需要先求获利的和,然后减去代价即可。
我们对于第i个人来说, 如果选他,会耗费A[I]的代价,那么(source,i,a[i])代表选他之后的代价,如果不选他,我们会产生Σw[i][j] 1<=j<=n的代价,也就是这么多的利益我们无法得到,然后对于两个人的互相影响,连边(i,j,2*w[i][j]),代表如果不选i,选j的话,本来i中选j的利益得不到,又要损失j对i的影响为w[i][j]。所以共计损失2*w[i][j]。之后求最小割=最大流就行了。
/**************************************************************
Problem: 2039
User: BLADEVIL
Language: Pascal
Result: Accepted
Time:860 ms
Memory:47112 kb
****************************************************************/
//By BLADEVIL
var
n :longint;
pre, other, len :array[0..4000010] of longint;
last :array[0..1010] of longint;
l :longint;
source, sink :longint;
que, d :array[0..1010] of longint;
ans :longint;
function min(a,b:longint):longint;
begin
if a>b then min:=b else min:=a;
end;
procedure connect(x,y,z:longint);
begin
inc(l);
pre[l]:=last[x];
last[x]:=l;
other[l]:=y;
len[l]:=z;
end;
procedure init;
var
i, j :longint;
x :longint;
sum :longint;
begin
read(n);
source:=n+2; sink:=source+1; l:=1;
for i:=1 to n do
begin
read(x);
connect(source,i,x);
connect(i,source,0);
end;
for i:=1 to n do
begin
sum:=0;
for j:=1 to n do
begin
read(x);
if x=0 then continue;
sum:=sum+x;
connect(i,j,x<<1);
connect(j,i,0);
ans:=ans+x;
end;
connect(i,sink,sum);
connect(sink,i,0);
end;
end;
function bfs:boolean;
var
h, t, cur :longint;
q, p :longint;
begin
fillchar(d,sizeof(d),0);
h:=0; t:=1;
que[1]:=source;
d[source]:=1;
while h<t do
begin
inc(h);
cur:=que[h];
q:=last[cur];
while q<>0 do
begin
p:=other[q];
if (len[q]>0) and (d[p]=0) then
begin
inc(t);
que[t]:=p;
d[p]:=d[cur]+1;
if p=sink then exit(true);
end;
q:=pre[q];
end;
end;
exit(false);
end;
function dinic(x,flow:longint):longint;
var
rest, tmp :longint;
q, p :longint;
begin
if x=sink then exit(flow);
rest:=flow;
q:=last[x];
while q<>0 do
begin
p:=other[q];
if (len[q]>0) and (d[p]=d[x]+1) and (rest>0) then
begin
tmp:=dinic(p,min(len[q],rest));
dec(rest,tmp);
dec(len[q],tmp);
inc(len[q xor 1],tmp);
end;
q:=pre[q];
end;
exit(flow-rest);
end;
procedure main;
begin
while bfs do ans:=ans-dinic(source,maxlongint div 10);
writeln(ans);
end;
begin
init;
main;
end.
bzoj 2039 最小割模型的更多相关文章
- bzoj 1497 最小割模型
我们可以对于消费和盈利的点建立二分图,开始答案为所有的盈利和, 那么源向消费的点连边,流量为消费值,盈利向汇连边,流量为盈利值 中间盈利对应的消费连边,流量为INF,那么我们求这张图的最小割,用 开始 ...
- 2019 HDU 多校赛第二场 HDU 6598 Harmonious Army 构造最小割模型
题意: 有n个士兵,你可以选择让它成为战士还是法师. 有m对关系,u和v 如果同时为战士那么你可以获得a的权值 如果同时为法师,你可以获得c的权值, 如果一个为战士一个是法师,你可以获得b的权值 问你 ...
- 【BZOJ 3144】 3144: [Hnoi2013]切糕 (最小割模型)
3144: [Hnoi2013]切糕 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1764 Solved: 965 Description Inp ...
- HDU 6634 网络流最小割模型 启发式合并
如果我们先手拿完所有苹果再去考虑花费的话. S -> 摄像头 -> 苹果 -> T 就相当于找到一个最小割使得S和T分开. ans = sum - flow. 然后对于这一个模型, ...
- BZOJ 1412 & 最小割
什么时候ZJ省选再现一次这么良心的题吧... 题意: 在一个染色的格子画分割线,使其不想连,求最少的线段 SOL: 裸裸的最小割.题目要求两种颜色不想连,我们把他分到两个集合,也就是把所有相连的边切断 ...
- BZOJ 1797 最小割
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1797 题意:给出一个有向图,每条边有流量,给出源点汇点s.t.对于每条边,询问:(1)是 ...
- BZOJ 2229 最小割
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2229 题意:给定一个带权无向图.若干询问,每个询问回答有多少点对(s,t)满足s和t的最 ...
- tyvj P1209 - 拦截导弹 平面图最小割&&模型转化
P1209 - 拦截导弹 From admin Normal (OI)总时限:6s 内存限制:128MB 代码长度限制:64KB 背景 Background 实中编程者联盟为了培养技 ...
- bzoj 1934 最小割
收获: 1.流量为0的边可以不加入. 2.最小割方案要与决策方案对应. #include <cstdio> #include <cmath> #include <cstr ...
随机推荐
- 零基础学习Vim编辑器
**********************************************************************0.这篇教程的简介:Vim是Linux/Unix下的经典编辑 ...
- Linux-OpenSUSE折腾-1(Qt安装,Chrome安装)
先上图,大蜥蜴还是不错的,偶然看到了大蜥蜴这个系统,我就觉得又可以折腾几天了,先上图 OpenSUSE有一个入门介绍的网站写的相当不错,感兴趣的可以连接过去:https://lug.ustc.edu. ...
- Spring实战第五章学习笔记————构建Spring Web应用程序
Spring实战第五章学习笔记----构建Spring Web应用程序 Spring MVC基于模型-视图-控制器(Model-View-Controller)模式实现,它能够构建像Spring框架那 ...
- 基于Ubuntu搭建Linux路由器
开源,几乎代表了无所不能的意思,最近又因为它玩Hi了... 因业务发展,需要临时接入300MB的专线和千兆路由器,而公司现有的路由器却是百兆的,出于成本考虑,只能不想更换新的路由器,在网上查了一下可以 ...
- HDU 3689 Infinite monkey theorem(DP+trie+自动机)(2010 Asia Hangzhou Regional Contest)
Description Could you imaging a monkey writing computer programs? Surely monkeys are smart among ani ...
- HDU 4582 DFS spanning tree(DFS+贪心)(2013ACM-ICPC杭州赛区全国邀请赛)
Problem Description Consider a Depth-First-Search(DFS) spanning tree T of a undirected connected gra ...
- centos7.4内核从3.10升级到4.14详细步骤
由于我们的docker学习中的Overlay需要内核版本在3.12+,所以在安装完centos7.4之后要进行内核升级,下面是升级步骤:1.导入keyrpm --import https://www. ...
- systemPath
<dependency> <groupId>com.aliyun.mns</groupId> <artifactId>aliyun-sdk-mn ...
- vsCode怎么为一个前端项目配置ts的运行环境
vsCode为一个前端项目配置ts的运行环境,ts文件保存的时候自动编译成js文件: 假设此前端项目名称为Web:文件结构如图 1. 在根目录中新建一个“.vscode”文件夹,里面建一个“tasks ...
- Angular 表单验证 基础篇
<div class="nav"> <h4>表单验证</h4> <form ng-app="myApp" name=& ...