bzoj 1221: [HNOI2001] 软件开发 (网络流)
注意说如果直接从每天的新的连向旧的,那整个图的最大流还是不变,答案就一直会是Σni*f
type
arr=record
toward,next,cap,cost:longint;
end;
const
maxm=;
maxn=;
var
edge:array[..maxm]of arr;
dist,first,slack:array[..maxn]of longint;
chose:array[..maxn]of boolean;
n,m,s,t,tot,esum,i,maxflow,maxcost: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,dist[s]*flow);
exit(flow);
end;
now:=;
chose[x]:=true;
i:=first[x];
while i>= do begin
too:=edge[i].toward;
value:=edge[i].cost;
if (edge[i].cap>) and (not chose[too]) then
if dist[x]=dist[too]+value then begin
more:=aug(too,min(edge[i].cap,flow-now));
dec(edge[i].cap,more);
inc(edge[i xor ].cap,more);
inc(now,more);
if now=flow then exit(flow);
end
else
slack[too]:=min(slack[too],dist[too]+value-dist[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=maxlongint then exit(false);
for i:= to tot do
if chose[i] then inc(dist[i],spent);
exit(true);
end; procedure into;
var
n,timea,timeb,cost1,costa,costb,i,j:longint;
begin
readln(n,timea,timeb,cost1,costa,costb);
fillchar(first,sizeof(first),);
esum:=-;
s:=n<<+;
t:=n<<+;
tot:=t;
for i:= to n do begin
read(j);
addedge(s,i,j,cost1);
addedge(s,i+n,j,);
addedge(i,t,j,);
end;
for i:= to n do begin
for j:=i+timea+ to n do
addedge(i+n,j,maxlongint,costa);
for j:=i+timeb+ to n do
addedge(i+n,j,maxlongint,costb);
end;
end; begin
into;
repeat
for i:= to tot do slack[i]:=maxlongint;
repeat
fillchar(chose,sizeof(chose),false);
until aug(s,maxlongint)<=;
until not rel;
writeln(maxcost);
readln;
readln;
end.
bzoj 1221: [HNOI2001] 软件开发 (网络流)的更多相关文章
- BZOJ 3280: 小R的烦恼 & BZOJ 1221: [HNOI2001] 软件开发
3280: 小R的烦恼 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 399 Solved: 200[Submit][Status][Discuss ...
- BZOJ 1221: [HNOI2001] 软件开发
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1428 Solved: 791[Submit][Stat ...
- BZOJ 1221: [HNOI2001] 软件开发(最小费用最大流)
不知道为什么这么慢.... 费用流,拆点.... --------------------------------------------------------------------------- ...
- bzoj 1221 [HNOI2001] 软件开发 费用流
[HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1938 Solved: 1118[Submit][Status][D ...
- [BZOJ 1221] [HNOI2001] 软件开发 【费用流 || 三分】
题目链接:BZOJ - 1221 题目分析 算法一:最小费用最大流 首先这是一道经典的网络流问题.每天建立两个节点,一个 i 表示使用毛巾,一个 i' 表示这天用过的毛巾. 然后 i 向 T 连 Ai ...
- BZOJ 1221: [HNOI2001] 软件开发【最小费用最大流】
Description 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员 ...
- BZOJ 1221 [HNOI2001] 软件开发 费用流_建模
题目描述: 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供 ...
- BZOJ 1221 [HNOI2001] 软件开发(费用流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1221 [题目大意] 每天对毛巾都有一定的需求ni,每天可以花f价值每条购买毛巾, 当天 ...
- 【BZOJ 1221】 1221: [HNOI2001] 软件开发 (最小费用流)
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1581 Solved: 891 Description ...
随机推荐
- LeetCode:33. Search in Rotated Sorted Array(Medium)
1. 原题链接 https://leetcode.com/problems/search-in-rotated-sorted-array/description/ 2. 题目要求 给定一个按升序排列的 ...
- GoF设计模式
GOF23种设计模式简介 GoF(“四人帮”,指Gamma, Helm, Johnson & Vlissides, Addison-Wesley四人)提出的23种设计模式可谓经典,由于其定义比 ...
- linux下免安装版本mysql5.5 配置
进入/usr/local #cd /usr/local 下载 #wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.39-linux ...
- Clojure基础课程2-Clojure中的数据长啥样?
本文来自网易云社区 作者:李诺 " Clojure is elegant and pragmatic; it helps me focus more on solving business ...
- sql注入--高权限,load_file读写文件
select '<?php eval($_POST[123]) ?>' into outfile '/var/www/html/1.php'; 1.MYSQL新特性限制文件写入及替代方法 ...
- Linux命令应用大词典-第11章 Shell编程
11.1 declare:显示或设置Shell变量 11.2 export:显示或设置环境变量 11.3 set:显示和设置Shell变量 11.4 unset:删除变量或函数 11.5 env:查看 ...
- 关于java中的“error: bad operand types for binary operator ”
今天做这个题目的时候(142. O(1) Check Power of 2),遇到一个错误“ bad operand types for binary operator '&' ”. 先贴一下 ...
- 浪在ACM新春大作战
题目链接: # Name 补题状态 A Memory and Crow 已补 B Memory and Trident 已补 C Memory and De-Evolution 已补 D Memory ...
- Linux内核设计笔记10——内核同步
Linux内核同步笔记 几个基本概念 - 临界区(critical region):访问和操作共享数据的代码段: - 原子操作:操作在执行中不被打断,要么不执行,要么执行完: - 竞争条件: 两个线程 ...
- POJ 1741 Tree(树的分治)
Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Def ...