bzoj 1458 最大流
来源:互联网 发布:淘宝宠物用品店铺介绍 编辑:程序博客网 时间:2024/05/22 15:11
题意:有一个M * N的棋盘,有的格子是障碍。现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里不能放置士兵。我们称这些士兵占领了整个棋盘当满足第i行至少放置了Li个士兵, 第j列至少放置了Cj个士兵。现在你的任务是要求使用最少个数的士兵来占领整个棋盘。
题目要求用的最少,转化一下即不用的最多
即 先放满棋盘,然后考虑最多可以拿走多少个
最大流,初始化答案为所有可以放的格子数
显然,当某一行或某一列的可以放的格子数小于需求就直接jiong掉
考虑,由于每在(x,y)放置一个士兵,对第x行和第y列都会有贡献
建图:
S -> 每一行 容量为可以放的格子数- 最少放置格子数 (即容量为第i行最多可以拿走的数量)
每一列 -> T 容量为可以放的格子数- 最少放置格子数(即容量为第j列最多可以拿走的数量)
每一个可以放的格子(i,j) i -> j 容量为1
最终答案为 ans-maxflow
var n,m,l,x,y,k :longint; ss,st,ans :longint; i,j :longint; flag :array[0..110,0..110] of boolean; que,dis,last,a,b:array[0..210] of longint; pre,other,len :array[0..20505] of longint;function min(a,b:longint):longint;begin if a<b then exit(a) else exit(b);end;procedure connect(x,y,z:longint);begin inc(l); pre[l]:=last[x]; last[x]:=l; other[l]:=y; len[l]:=z;end;function bfs:boolean;var h,tl,i,p,q,cur:longint;begin fillchar(dis,sizeof(dis),0); h:=0; tl:=1; que[1]:=ss; dis[ss]:=1; while (h<>tl) do begin h:=h mod 205+1; cur:=que[h]; q:=last[cur]; while (q<>0) do begin p:=other[q]; if (dis[p]=0) and (len[q]>0) then begin dis[p]:=dis[cur]+1; tl:=tl mod 205+1; que[tl]:=p; if p=st then exit(true); end; q:=pre[q]; end; end; exit(false);end;function dinic(x,flow:longint):longint;var rest,tt,p,q:longint;begin if x=st then exit(flow); rest:=flow; q:=last[x]; while (q<>0) do begin p:=other[q]; if (dis[p]=dis[x]+1) and (len[q]>0) and (rest>0) then begin tt:=dinic(p,min(rest,len[q])); dec(len[q],tt); inc(len[q xor 1],tt); dec(rest,tt); if rest=0 then exit(flow); end; q:=pre[q]; end; if rest=flow then dis[x]:=0; exit(flow-rest);end;begin read(n,m,k); l:=1; ans:=n*m-k; ss:=n+m+1; st:=ss+1; for i:=1 to n do begin read(x); a[i]:=m-x; end; for i:=1 to m do begin read(x); b[i]:=n-x; end; // for i:=1 to k do begin read(x,y); dec(a[x]); dec(b[y]); flag[x,y]:=true; if (a[x]<0) or (b[y]<0) then begin writeln('JIONG!');exit; end; end; // for i:=1 to n do begin connect(ss,i,a[i]); connect(i,ss,0); end; for i:=1 to m do begin connect(n+i,st,b[i]); connect(st,n+i,0); end; for i:=1 to n do for j:=1 to m do if not flag[i,j] then begin connect(i,n+j,1); connect(n+j,i,0); end; // while bfs do dec(ans,dinic(ss,maxlongint div 10)); writeln(ans);end.——by Eirlys
0 0
- bzoj 1458 最大流
- BZOJ 1458 士兵占领 Dinic最大流
- 【bzoj 1458】士兵占领(最大流)
- BZOJ 1458: 士兵占领 网络最大流
- BZOJ 1458: 士兵占领 最大流
- BZOJ 1458: 士兵占领 最大流 题解
- 【bzoj 1458】士兵占领(最大流)
- [最大流] BZOJ 1458: 士兵占领 题解
- BZOJ 1066 最大流
- bzoj 1066 最大流
- bzoj 1711 最大流
- BZOJ 3931 最大流
- BZOJ 4514 浅谈最大费用最大流
- bzoj 2661(最大费用流)
- bzoj 1532(二分+最大流)
- bzoj 3931(spfa+最大流)
- bzoj 1066 蜥蜴(最大流)
- bzoj 1066 蜥蜴 最大流
- Oracle数据库学习笔记(一)之单行函数
- [substence designer]最近做的几个PBR材质
- Android解决部分机型获取不到系统拍照图片,图库图片问题的解决
- bzoj2705: [SDOI2012]Longge的问题
- 教你学会怎样编辑操作PDF文件
- bzoj 1458 最大流
- java 文件操作工具类
- iOS pop动画的入门使用
- [poj]3187 Backward Digit Sums [dfs]
- Android性能调优工具TraceView介绍
- 102. Binary Tree Level Order Traversal
- poj-2485 Highways
- 基于openwrt 编写自己的Helloworld程序
- 运筹学 —线性规划总结