bzoj 2245 费用流
比较裸
源点连人,每个人连自己的工作,工作连汇,然后因为人的费用是
分度的,且是随工作数非降的,所以我们拆边,源点连到每个人s+1条边
容量是每段的件数,费用是愤怒
/**************************************************************
Problem:
User: BLADEVIL
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/
//By BLADEVIL
var
n, m :longint;
pre, other, len, cost :array[..] of longint;
last :array[..] of longint;
source, sink :longint;
time :array[..] of longint;
ans :int64;
father, dis, que :array[..] of longint;
flag :array[..] of boolean;
l :longint;
function min(a,b:longint):longint;
begin
if a>b then min:=b else min:=a;
end;
procedure connect(a,b,c,d:longint);
begin
inc(l);
pre[l]:=last[a];
last[a]:=l;
other[l]:=b;
len[l]:=c;
cost[l]:=d;
end;
procedure init;
var
i, j :longint;
x, y :longint;
begin
read(m,n);
l:=;
source:=n+m+; sink:=source+;
for i:= to n do
begin
read(x);
connect(m+i,sink,x,);
connect(sink,m+i,,);
end;
for i:= to m do
for j:= to n do
begin
read(x);
if x= then
begin
connect(i,j+m,maxlongint div ,);
connect(j+m,i,,);
end;
end;
for i:= to m do
begin
read(x);
for j:= to x do read(time[j]);
time[]:=;
time[x+]:=maxlongint div ;
for j:= to x+ do
begin
read(y);
connect(source,i,time[j]-time[j-],y);
connect(i,source,,-y);
end;
end;
end;
function spfa:boolean;
var
h, t, cur :longint;
q, p :longint;
begin
filldword(dis,sizeof(dis) div ,maxlongint div );
h:=; t:=;
que[]:=source;
dis[source]:=;
while h<>t do
begin
h:=h mod +;
cur:=que[h];
flag[cur]:=false;
q:=last[cur];
while q<> do
begin
if len[q]> then
begin
p:=other[q];
if dis[p]>dis[cur]+cost[q] then
begin
dis[p]:=dis[cur]+cost[q];
father[p]:=q;
if not flag[p] then
begin
t:=t mod +;
que[t]:=p;
flag[p]:=true;
end;
end;
end;
q:=pre[q];
end;
end;
if dis[sink]=maxlongint div then exit(false) else exit(true);
end;
procedure update;
var
low :longint;
cur :longint;
begin
cur:=sink;
low:=maxlongint;
while cur<>source do
begin
low:=min(low,len[father[cur]]);
cur:=other[father[cur] xor ];
end;
cur:=sink;
while cur<>source do
begin
dec(len[father[cur]],low);
inc(len[father[cur] xor ],low);
ans:=ans+low*cost[father[cur]];
cur:=other[father[cur] xor ];
end;
end;
procedure main;
begin
while spfa do
update;
writeln(ans);
end;
begin
init;
main;
end.
bzoj 2245 费用流的更多相关文章
- bzoj 3171 费用流
每个格拆成两个点,出点连能到的点的入点,如果是箭头指向 方向费用就是0,要不就是1,源点连所有出点,所有入点连 汇点,然后费用流 /********************************** ...
- bzoj 1449 费用流
思路:先把没有进行的场次规定双方都为负,对于x胜y负 变为x + 1胜 y - 1 负所需要的代价为 2 * C[ i ] * x - 2 * D[ i ] * y + C[ i ] + D[ i ...
- BZOJ 1061费用流
思路: 我们可以列出几个不等式 用y0带进去变成等式 下-上 可以消好多东西 我们发现 等式左边的加起来=0 可以把每个方程看成一个点 正->负 连边 跑费用流即可 //By SiriusRen ...
- BZOJ 1283 费用流
思路: 最大费用最大流 i->i+1 连边k 费用0 i->i+m (大于n的时候就连到汇) 连边1 费用a[i] //By SiriusRen #include <queue> ...
- bzoj 1070 费用流
//可以网络流,但是要怎么分配每辆车让谁维修以及维修顺序呢.可以考虑每辆车维修时间对总结果的贡献,把每个修车人拆成n个点共n*m个点, //n辆车连向这n*m个点,流量1,费用k*修车时间,其中k(1 ...
- bzoj 2668 费用流
我们可以把初始状态转化为目标状态这一约束转化为将黑子移动到目标状态所需要的最少步数. 除了初始点和目标点之外,剩下的点如果被经过那么就会被交换两次,所以我们将一个点拆成3个点,a,b,c,新建附加源点 ...
- BZOJ 3280 费用流
思路: 同BZOJ 1221 //By SiriusRen #include <queue> #include <cstdio> #include <cstring> ...
- BZOJ 4514 费用流
思路: 懒得写了 http://blog.csdn.net/werkeytom_ftd/article/details/51277482 //By SiriusRen #include <que ...
- BZOJ 2245: [SDOI2011]工作安排( 费用流 )
费用流模板题..限制一下不同愤怒值的工作数就可以了. ------------------------------------------------------------------------- ...
随机推荐
- Vue学习(三):数据绑定语法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Qt 解析网络数据出现ssl错误
最近写了点小东西,哈哈, 网络部分是同学帮我搞的 在编译的时候,出现了一下错误 qt.network.ssl: QSslSocket: cannot call unresolved function ...
- c# 3D图形处理库
C#的OpenGL类库SharpGL SharpGL 可以让你在 Windows Forms 或者 WPF 应用中轻松的使用 OpenGL 开发图形应用.更多SharpGL信息 Axiom 3D En ...
- centos7安装python3.7
Centos7安装Python3的方法 由于centos7原本就安装了Python2,而且这个Python2不能被删除,因为有很多系统命令,比如yum都要用到. [root@VM_105_217_ ...
- Gym101981I Magic Potion(最大流)
Problem I. Magic Potion There are n heroes and m monsters living in an island. The monsters became v ...
- web开发速查表(php,css,html5........)
- python类学习以及mro--多继承属性查找机制
版权声明:本文为博主原创文章,未经博主允许不得转载. 还记得什么是新式类和旧式类吗? Python中,一个class继承于object,或其bases class里面任意一个继承于object,这个c ...
- poj3026(bfs+prim)最小生成树
The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. ...
- js把字符串格式的时间转换成几秒前、几分钟前、几小时前、几天前等格式
最近在做项目的时候,需要把后台返回的时间转换成几秒前.几分钟前.几小时前.几天前等的格式:后台返回的时间格式为:2015-07-30 09:36:10,需要根据当前的时间与返回的时间进行对比,最后显示 ...
- JavaScript内置对象常用
Math 提供了数学中常用的属性和方法,使用时直接用Math.属性/方法,而不需要new一个Math对象 Date 使用Date对象来对日期和时间进行操作.使用时,必须用new创建一个实例 windo ...