bzoj 2424: [HAOI2010]订货 (费用流)
直接费用流,天数就是点数
type
arr=record
toward,next,cap,cost:longint;
end;
const
maxm=;
maxn=;
mm=<<;
var
edge:array[..maxm]of arr;
first,slack,d:array[..maxn]of longint;
chose:array[..maxn]of boolean;
n,maxflow,maxcost,s,t,tot,esum:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure add(i,j,k,l:longint);
begin
inc(esum);
edge[esum].toward:=j;
edge[esum].next:=first[i];
first[i]:=esum;
edge[esum].cap:=k;
edge[esum].cost:=l;
end; procedure addedge(i,j,k,l:longint);
begin
add(i,j,k,l);
add(j,i,,-l);
end; function aug(x,flow:longint):longint;
var
now,more,i,too,value:longint;
begin
if x=t then begin
inc(maxflow,flow);
inc(maxcost,flow*d[s]);
exit(flow);
end;
chose[x]:=true;
i:=first[x];
now:=;
while i>= do begin
too:=edge[i].toward;
value:=edge[i].cost;
if (edge[i].cap>) and (not chose[too]) then
if d[x]=d[too]+value then begin
more:=aug(too,min(flow-now,edge[i].cap));
dec(edge[i].cap,more);
inc(edge[i xor ].cap,more);
inc(now,more);
if flow=now then exit(flow);
end
else
slack[too]:=min(slack[too],d[too]+value-d[x]);
i:=edge[i].next;
end;
exit(now);
end; function rel:boolean;
var
i,spent:longint;
begin
spent:=maxlongint;
for i:= to tot do
if not chose[i] then spent:=min(spent,slack[i]);
if spent>=mm then exit(false);
for i:= to tot do
if chose[i] then inc(d[i],spent);
exit(true);
end; procedure into;
var
i,j,k,m,sum:longint;
begin
esum:=-;
fillchar(first,sizeof(first),);
readln(n,m,sum);
tot:=n+;
s:=tot-;
t:=tot;
for i:= to n do begin
read(j);
addedge(i,t,j,);
end;
for i:= to n do begin
read(j);
addedge(s,i,maxlongint,j);
end;
for i:= to n- do
addedge(i,i+,sum,m);
end; begin
into;
fillchar(d,sizeof(d),);
maxflow:=;
maxcost:=;
repeat
fillchar(slack,sizeof(slack),$7f);
repeat
fillchar(chose,sizeof(chose),false);
until aug(s,maxlongint)<=;
until not rel;
writeln(maxcost);
readln;
readln;
end.
bzoj 2424: [HAOI2010]订货 (费用流)的更多相关文章
- BZOJ 2424: [HAOI2010]订货 费用流
2424: [HAOI2010]订货 Description 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月 ...
- BZOJ 2424: [HAOI2010]订货(最小费用最大流)
最小费用最大流..乱搞即可 ------------------------------------------------------------------------------ #includ ...
- BZOJ 2424: [HAOI2010]订货
2424: [HAOI2010]订货 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 915 Solved: 639[Submit][Status][ ...
- BZOJ 2424: [HAOI2010]订货(费用流)
裸的费用流了= =从源点向每个点连费用为di,从汇点向每个点连流量为ui,每个点向下一个点连费用为m,流量为s的边就行了 CODE: #include<cstdio>#include< ...
- 【bzoj2424】[HAOI2010]订货 费用流
原文地址:http://www.cnblogs.com/GXZlegend/p/6825296.html 题目描述 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di, ...
- BZOJ2424 [HAOI2010]订货 - 费用流
题解 (非常裸的费用流 题意有一点表明不清: 该月卖出的商品可以不用算进仓库里面. 然后套上费用流模板 代码 #include<cstring> #include<queue> ...
- BZOJ 2424 DP OR 费用流
思路: 1.DP f[i][j]表示第i个月的月底 还剩j的容量 转移还是相对比较好想的-- f[i][j+1]=min(f[i][j+1],f[i][j]+d[i]); if(j>=u[i+1 ...
- 2424: [HAOI2010]订货
2424: [HAOI2010]订货 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 922 Solved: 642[Submit][Status][ ...
- [bzoj 1449] 球队收益(费用流)
[bzoj 1449] 球队收益(费用流) Description Input Output 一个整数表示联盟里所有球队收益之和的最小值. Sample Input 3 3 1 0 2 1 1 1 1 ...
随机推荐
- LeetCode:39. Combination Sum(Medium)
1. 原题链接 https://leetcode.com/problems/combination-sum/description/ 2. 题目要求 给定一个整型数组candidates[ ]和目标值 ...
- 「日常训练」Uncle Tom's Inherited Land*(HDU-1507)
题意与分析 题意是这样的:给你一个\(N\times M\)的图,其中有一些点不能放置\(1\times 2\)大小的矩形,矩形可以横着放可以竖着放,问剩下的格子中,最多能够放多少个矩形. 注意到是\ ...
- postman使用感言
这段时间接口测试一直使用的postman,一款谷歌接口测试插件,感受如下 优点: 1.对于中小型公司来说应该是够用的,特别是一键接口环境切换,一键设置header,作为一般的接口测试来说已经很不错了, ...
- 为什么测试人员必须掌握Linux?
相信点进来的小伙伴不是对Linux感兴趣就是对测试感兴趣了,也希望本文可以帮助之前接触过Linux的小伙伴找到继续坚持学习下去的动力,之前没接触过Linux的小伙伴也能找到开始学习Linux的兴趣. ...
- python基本数据类型——集合
集合 无序可变序列,集合中元素不允许重复,即每个元素都是唯一的 集合中的元素按照升序排列 # 创建集合 >>aset = set([0,2,4,5,7,2,3,5,9,0]) >&g ...
- Android开发-API指南-<receiver>
<receiver> 英文原文:http://developer.android.com/guide/topics/manifest/receiver-element.html 采集(更新 ...
- LeetCode 138——复制带随机指针的链表
1. 题目 2. 解答 第一次遍历链表的时候,复制旧链表的节点值建立一个新的链表,同时定义一个 unordered_map 作为哈希表,哈希表的键为旧链表的节点指针,值为新链表的节点指针. 然后,第二 ...
- 【转载】OpenCV(C++ 与 Python 的比较)与 MATLAB 的比较
原文作者 : Satya Mallick 译者 : aleen42 原文 https://aleen42.gitbooks.io/personalwiki/content/translation/o ...
- Asp.net之数组应用
string[] abc=new string[8]{"1","2","3","4","1",&qu ...
- Python3 小工具-UDP发现
from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/UDP( ...