这题是基于一道经典的费用流模型。

将每天拆成两个点i和j,新增源和汇并建立六种边:

1.从源出发到每个i点,flow为+∞,cost为每条新餐巾的价值,表示这一天所使用的餐巾中来自购买的餐巾

2.从源出发到每个j点,flow为每天所需的餐巾数,cost为0,表示这一天最多可使用的餐巾

3.从每个i点出发至汇,flow为每天所需的餐巾数,cost为0,表示这一天应该使用的餐巾

4.从每个j点出发至下一个j点,flow为+∞,cost为0,表示这一天使用后的餐巾移至下一天

5.从每个j点出发至下a个i点,flow为+∞,cost为第一种消毒的费用,表示这一天所使用的餐巾中来自第一种消毒后的餐巾

6.从每个j点出发至下b个i点,flow为+∞,cost为第二种消毒的费用,表示这一天所使用的餐巾中来自第二种消毒后的餐巾

然后最小费用最大流跑之。

基于图的稀疏,我用ZKW费用流实现。

#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define clr(x, c) memset(x, c, sizeof(c))
#define travel(x) for(edge *p=fir[x]; p; p=p->n) if (p->f)
#define pb push_back
#define pf push_front
#define maxv 2009
#define maxm 30009
#define inf 0x7fffffff
int read()
{
int x=0; char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
return x;
} struct edge{int y, f, c; edge *n, *pair;} e[maxm], *fir[maxv], *pt;
inline void Init(){pt=e; clr(fir, 0);}
inline void Add(int x, int y, int f, int c)
{pt->y=y, pt->f=f, pt->c=c, pt->n=fir[x]; fir[x]=pt++;}
inline void AddE(int x, int y, int f, int c)
{Add(x, y, f, c); Add(y, x, 0, -c); fir[x]->pair=fir[y], fir[y]->pair=fir[x];}
int S, T, V, d[maxv]; ll cost=0;
int dist[maxv], st[maxv];
bool b[maxv];
deque <int> q;
inline void spfa()
{
rep(i, 1, V) d[i]=inf, b[i]=0; q.clear();
q.pb(S), d[S]=0, b[S]=1;
while (!q.empty())
{
int x=q.front(), y; q.pop_front(); b[x]=0;
travel(x) if (d[y=p->y] > d[x]+p->c)
{
d[y]=d[x]+p->c;
if (!b[y]) b[y]=1, (!q.empty() && d[q.front()]>d[y]) ? q.pf(y) : q.pb(y);
}
}
}
void dfs(int now)
{
b[now]=1; int y;
travel(now)
if (d[now]+p->c==d[y=p->y] && !b[y])
dist[y]=dist[now]-p->c, dfs(y);
}
int aug(int now, int flow)
{
if (now==T) {cost+=flow*(dist[S]-dist[T]); return flow;}
b[now]=1; int rec=0, y, ret;
travel(now) if (!b[y=p->y])
{
if (dist[now]==dist[y]+p->c)
{
ret=aug(y, min(flow-rec, p->f));
p->f-=ret, p->pair->f+=ret;
if ((rec+=ret)==flow) return flow;
}
else st[y]=min(st[y], dist[y]+p->c-dist[now]);
}
return rec;
}
inline bool relabel()
{
int a=inf;
rep(i, 1, V) if (!b[i]) a=min(a, st[i]);
if (a==inf) return 0;
rep(i, 1, V) if (b[i]) dist[i]+=a;
return 1;
}
inline void costflow()
{
spfa();
clr(b, 0); clr(dist, 0);
dfs(S);
while(1)
{
rep(i, 1, V) st[i]=inf;
while(1)
{
rep(i, 1, V) b[i]=0;//clr(b, 0);
if (!aug(S, inf)) break;
}
if (!relabel()) break;
}
} int n;
int main(){
Init(); n=read(); S=n*2+1; T=V=n*2+2;
int a=read(), b=read(), f=read(), fa=read(), fb=read();
rep(i, 1, n-a) AddE(i*2, (i+a+1)*2-1, inf, fa);
rep(i, 1, n-b) AddE(i*2, (i+b+1)*2-1, inf, fb);
rep(i, 1, n) a=read(), AddE(S, i*2-1, inf, f), AddE(S, i*2, a, 0), AddE(i*2-1, T, a, 0);
rep(i, 1, n-1) AddE(i*2, i*2+2, inf, 0);
costflow(); printf("%lld\n", cost);
return 0;
}

BZOJ-1221 软件开发的更多相关文章

  1. BZOJ 1221 软件开发(费用流)

    容易看出这是显然的费用流模型. 把每天需要的餐巾数作为限制.需要将天数拆点,x’表示每天需要的餐巾,x’’表示每天用完的餐巾.所以加边 (s,x',INF,0),(x'',t,INF,0). 餐巾可以 ...

  2. 【BZOJ】【1221】【HNOI2001】软件开发

    网络流/费用流 说是这题跟餐巾计划一模一样……但我没做过啊……so sad 二分图建模是很好想的,但是要控制流量跟用了的毛巾一样多……oh my god 事实上对于每一天我们无论如何都是要消耗n[i] ...

  3. BZOJ 1221: [HNOI2001] 软件开发

    1221: [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1428  Solved: 791[Submit][Stat ...

  4. 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1221 先吐槽一下,数组依旧开小了RE:在spfa中用了memset和<queue>的版本 ...

  5. BZOJ 3280: 小R的烦恼 & BZOJ 1221: [HNOI2001] 软件开发

    3280: 小R的烦恼 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 399  Solved: 200[Submit][Status][Discuss ...

  6. BZOJ 1221: [HNOI2001] 软件开发(最小费用最大流)

    不知道为什么这么慢.... 费用流,拆点.... --------------------------------------------------------------------------- ...

  7. 【BZOJ 1221】 1221: [HNOI2001] 软件开发 (最小费用流)

    1221: [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1581  Solved: 891 Description ...

  8. [BZOJ 1221] [HNOI2001] 软件开发 【费用流 || 三分】

    题目链接:BZOJ - 1221 题目分析 算法一:最小费用最大流 首先这是一道经典的网络流问题.每天建立两个节点,一个 i 表示使用毛巾,一个 i' 表示这天用过的毛巾. 然后 i 向 T 连 Ai ...

  9. bzoj:1221;vijos 1552 软件开发

    Description 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员 ...

  10. bzoj 1221 [HNOI2001] 软件开发 费用流

    [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1938  Solved: 1118[Submit][Status][D ...

随机推荐

  1. 在DataGridView控件中隔行换色

    实现效果: 知识运用: DataGridViewRow类的公共属性DefaultCellStyle的BackColor属性 public Color BackColor {get; set;} 实现代 ...

  2. SQL Server将列以分隔符分割后存到临时表

    begin if object_id('tempdb..#t') is not null drop table #t; create table #t ( filepath ) ); declare ...

  3. C10 C语言数据结构

    目录 枚举 结构体 共用体 枚举 enum enum枚举是 C 语言中的一种基本数据类型,它可以让数据更简洁,更易读. 枚举语法定义格式为: enum 枚举名 {枚举元素1,枚举元素2,……}; 枚举 ...

  4. js菜鸟备忘

    1.图片切换 function changeImage() { var img = document.getElementById("myImg"); ")) img.s ...

  5. C#访问数组元素

    在C#中,使用索引来访问数组元素.索引必须是一个整型值. 在数组中,每一个维度的索引从0开始. 一.访问一维数组元素 int[] array = {1,2,3,4,5,6,7,8,9,10}; // ...

  6. 12_1_Annotation注解

    12_1_Annotation注解 1. 什么是注解 Annotation是从JDK5.0开始引入的新技术. Annotation的作用: 不是程序本身,可以对程序作出解释.可以被其他程序(比如,编译 ...

  7. Ping 命令的执行过程和应用协议

    1. ICMP是“Internet Control Message Ptotocol”的缩写.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制消息. 控制消息是指网络通不通.主机 ...

  8. 基于Inception搭建MySQL SQL审核平台Yearing

    基于Inception搭建MySQL SQL审核平台Yearing Inception 1. Inceptionj简介 2. Inception安装 2.1 下载和编译 2.2 启动配置 Yearni ...

  9. MySQL 自学笔记_Union(组合查询)

    1. Union查询简介 组合查询:有时在使用select语句进行数据查询时,想要将多个select语句在一个查询结果中输出,此时就需要使用Union关键字. Union的使用方法:用union将多个 ...

  10. ProC第二弹

    一.提要 上文简单介绍了Windows下ProC配置开发,这次我们使用Linux平台再次配置Oracle ProC开发环境(RedHat Linux 9 + Oracle 92).    <OR ...