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]工作安排( 费用流 )
费用流模板题..限制一下不同愤怒值的工作数就可以了. ------------------------------------------------------------------------- ...
随机推荐
- What to do when Enterprise Manager is not able to connect to the database instance (ORA-28001)
摘自:http://dbtricks.com/?p=34 If you are trying to connect to the Oracle enterprise Manger and you ge ...
- [网站日志]当Memcached缓存服务挂掉时性能监视器中的表现
我们用的Memcached缓存服务是阿里云OCS,今天晚上遇到了一次OCS挂掉的情况(计划中的升级),看一下性能监视器中的表现,也许对分析黑色1秒问题有帮助. 应用日志中错误: 2014-06-05 ...
- ASP.NET Web API 2 返回 Json格式
最近在学习ASP.NET的Web API,刚刚开始以为会有些复杂,结果却非常简单. 学习的地址:http://www.asp.net/web-api/overview/getting-started- ...
- 利用LD_PRELOAD进行hook
原文地址:http://hbprotoss.github.io/posts/li-yong-ld_preloadjin-xing-hook.html 好久没玩hook这种猥琐的东西里,今天在Linux ...
- MySQL高可用之MHA切换测试(switchover & failover)
Preface I've installed MasterHA yesterday,Now let's test the master-slave switch and failove ...
- 基于规则的中文分词 - NLP中文篇
之前在其他博客文章有提到如何对英文进行分词,也说后续会增加解释我们中文是如何分词的,我们都知道英文或者其他国家或者地区一些语言文字是词与词之间有空格(分隔符),这样子分词处理起来其实是要相对容易很多, ...
- 从零开始搭建一个react项目
Nav logo 120 发现 关注 消息 4 搜索 从零开始搭建一个react项目 96 瘦人假噜噜 2017.04.23 23:29* 字数 6330 阅读 32892评论 31喜欢 36 项目地 ...
- Hessian 2.0 序列化协议 - Hessian 2.0 Serialization Protocol 翻译
Hessian是一种轻量.快速的web协议,在微服务场景下经常被使用. Hessian协议实际上包含两种含义: 1. Web网络通信远程调用服务,具体可以参考:http://hessian.cauch ...
- OpenCV尺寸调整
#include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...
- CSS3基础选择器
/*选择器分组:多个选择器使用同一个样式*/ h1,h2,a{ color: blue; } strong{ color: aquamarine; } /*选择器继承:body中未设置样式的会使用继承 ...