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 ...
随机推荐
- Ruby 基础教程1-6
1.循环实现方法 循环语句 (while;for; loop,until) 循环方法(times,each) 2.for for 变量 in 对象 主体 ...
- 如何用istio实现应用的灰度发布
Istio为用户提供基于微服务的流量治理能力.Istio允许用户按照标准制定一套流量分发规则,并且无侵入的下发到实例中,平滑稳定的实现灰度发布功能. 基于华为云的Istio服务网格技术,使得灰度发布全 ...
- 第一篇 HTML基础
浏览网页,就是上网,上网的本质就是下载内容. 浏览器是个解释器,用来执行HTML.css.JS代码的. HTML,CSS, JavaScript 号称网络三剑客. 1. 浏览器发送一个域名给服务端 2 ...
- ortp代码简析
ortp初始化 /** * Initialize the oRTP library. You should call this function first before using * ...
- Samba共享权限分配
案例推荐:http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html 本文不详细介绍全部参数,只介绍完成需求的一些参数. 需求: 1,账 ...
- 为什么23种设计模式中没有MVC
GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software>/<设计 ...
- Notes of the scrum meeting before publishing2(12.18)
meeting time:18:30~20:30p.m.,December 18th,2013 meeting place:3号公寓一层 attendees: 顾育豪 ...
- Notes of the scrum meeting(12.9)
meeting time:14:00~17:00p.m.,December 9th,2013 meeting place:一号教学楼209 attendees: 顾育豪 ...
- A4
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 很胖,刚学,照猫画虎做了登录与注册界面. 展示GitHub ...
- Median of Two Sorted Arrays(hard)
题目要求: 有两个排序的数组nums1和nums2分别为m和n大小. 找到两个排序数组的中位数.整体运行时间复杂度应为O(log(m + n)). 示例: 我的方法: 分别逐个读取两个数组的数,放到一 ...