BZOJ1221 [HNOI2001] 软件开发 【费用流】

题目

某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供一块消毒毛巾,这种消毒毛巾使用一天后必须再做消毒处理后才能使用。消毒方式有两种,A种方式的消毒需要a天时间,B种方式的消毒需要b天(b>a),A种消毒方式的费用为每块毛巾fA, B种消毒方式的费用为每块毛巾fB,而买一块新毛巾的费用为f(新毛巾是已消毒的,当天可以使用);而且f>fA>fB。公司经理正在规划在这n天中,每天买多少块新毛巾、每天送多少块毛巾进行A种消毒和每天送多少块毛巾进行B种消毒。当然,公司经理希望费用最低。你的任务就是:为该软件公司计划每天买多少块毛巾、每天多少块毛巾进行A种消毒和多少毛巾进行B种消毒,使公司在这项n天的软件开发中,提供毛巾服务的总费用最低。

输入格式

第1行为n,a,b,f,fA,fB. 第2行为n1,n2,……,nn. (注:1≤f,fA,fB≤60,1≤n≤1000)

输出格式

最少费用

输入样例

4 1 2 3 2 1

8 2 1 6

输出样例

38

题解

除了送洗时间多算一天
同 餐厅计划问题

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<algorithm>
#define LL long long int
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
using namespace std;
const int maxn = 3005,maxm = 1000005,INF = 1000000000;
inline int read(){
    int out = 0,flag = 1; char c = getchar();
    while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
    while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
    return out * flag;
}
int h[maxn],ne = 2;
struct EDGE{int from,to,nxt,f,w;}ed[maxm];
inline void build(int u,int v,int f,int w){
    ed[ne] = (EDGE){u,v,h[u],f,w}; h[u] = ne++;
    ed[ne] = (EDGE){v,u,h[v],0,-w}; h[v] = ne++;
}
int S,T,d[maxn],p[maxn],minf[maxn],vis[maxn];
queue<int> q;
int mincost(){
    int flow = 0,cost = 0;
    while (true){
        for (int i = S; i <= T; i++) d[i] = INF,vis[i] = false;
        q.push(S); d[S] = 0; vis[S] = true; minf[S] = INF;
        int u;
        while (!q.empty()){
            u = q.front(); q.pop();
            vis[u] = false;
            Redge(u) if (ed[k].f && d[to = ed[k].to] > d[u] + ed[k].w){
                d[to] = d[u] + ed[k].w; minf[to] = min(minf[u],ed[k].f); p[to] = k;
                if (!vis[to]) q.push(to),vis[to] = true;
            }
        }
        if (d[T] == INF) break;
        flow += minf[T]; cost += minf[T] * d[T];
        u = T;
        while (u != S){
            ed[p[u]].f -= minf[T];
            ed[p[u] ^ 1].f += minf[T];
            u = ed[p[u]].from;
        }
    }
    return cost;
}
int n,a,b,f,fa,fb;
int main(){
    n = read(); a = read(); b = read(); f = read(); fa = read(); fb = read();
    S = 0; T = 3 * n + 1;
    for (int i = 1; i <= n; i++){
        int x = read();
        build(i,T,x,0);
        build(S,i + n,INF,0);
        build(i + n,i,INF,f);
        build(i + n,i + 2 * n,x,0);
        if (i + a <= n) build(i + 2 * n,i + a + 1,x,fa);
        if (i + b <= n) build(i + 2 * n,i + b + 1,x,fb);
        if (i < n) build(i,i + 1,INF,0);
    }
    printf("%d\n",mincost());
    return 0;
}

转载于:https://www.cnblogs.com/Mychael/p/8538835.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值