zoukankan      html  css  js  c++  java
  • 【BZOJ 1221】 [HNOI2001] 软件开发

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    ```cpp /* 设一个超级源点S和超级汇点T S和2*i-1各连一条容量为ni的边。 花费为0 表示每天都会产生ni条要洗的毛巾
    S和2*i各连一条容量为INF的边
        花费为f
        表示新买毛巾用
    
    2*i-1和2*(i+a)连容量为INF的边
        花费为fa
    
    2*i-1和2*(i+b)连容量为INF的边
        花费为fb
    
    表示用完的毛巾消毒。
    当然。用完的毛巾还能不马上消毒。
    所以
    2*i-1和2*(i+1)-1连容量为INF的边。花费为0
    
    然后对于2*i,每个点都和汇点T连容量为ni的边。
    表示每天要用的毛巾个数。
    
    这样满流的时候就是符合要求的了。
    跑个费用流就可以了。
    

    */

    **边数一定要谨慎算。。**
    </font>
    
    <font color = black size = 6> 【代码】</font>
    ```cpp
    #include <bits/stdc++.h>
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define all(x) x.begin(),x.end()
    #define pb push_back
    #define ms(x,y) memset(x,y,sizeof x)
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    using namespace std;
    
    const double pi = acos(-1);
    const int dx[4] = {0,0,1,-1};
    const int dy[4] = {1,-1,0,0};
    const int N = 2e3;
    const int M = 2e4;
    const int INF = 0x3f3f3f3f;
    
    struct abc{
        int from,en,flow,nex,cost;
    };
    
    int n,A,B,F,FA,FB,fir[N+100],dis[N+100],pre[N+100],mi[N+100],totm,a[N+100],ans;
    bool inq[N+10];
    queue<int> dl;
    abc bian[M];
    
    void add(int x,int y,int flow,int cost){
        bian[totm].nex = fir[x];
        fir[x] = totm;
        bian[totm].from = x;
        bian[totm].en = y;
        bian[totm].cost = cost;
        bian[totm].flow = flow;
        totm++;
    
        bian[totm].nex = fir[y];
        fir[y] = totm;
        bian[totm].from = y;
        bian[totm].en = x;
        bian[totm].cost = -cost;
        bian[totm].flow = 0;
        totm++;
    }
    
    bool spfa(int s,int t){
        ms(dis,INF),ms(inq,0),ms(mi,INF);
        dis[s] = 0,inq[s] = 1;
        dl.push(s);
        pre[t] = -1;
        while (!dl.empty()){
    
            int x = dl.front();
            inq[x] = false;
            dl.pop();
            for (int i = fir[x];i!=-1;i = bian[i].nex){
                int y = bian[i].en;
                if (bian[i].flow && dis[y] > dis[x] + bian[i].cost){
                    dis[y] = dis[x] + bian[i].cost;
                    mi[y] = min(bian[i].flow,mi[x]);
                    pre[y] = i;
                    if (!inq[y]){
                        inq[y] = true;
                        dl.push(y);
                    }
                }
            }
        }
        if (pre[t]==-1) return false;
        int now = t;
        while (now != s){
            int temp = pre[now];
            bian[temp].flow -= mi[t];
            bian[temp^1].flow += mi[t];
            now = bian[temp].from;
            ans += mi[t]*bian[temp].cost;
        }
        return true;
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
    	ms(fir,255);
        cin >> n >> A >> B >> F >> FA >> FB;
        for (int i = 1;i <= n;i++) cin >> a[i];
        for (int i = 1;i <= n;i++) {
            add(0,2*i-1,a[i],0);
            add(0,2*i,INF,F);
            if (i<n) add(2*i-1,2*(i+1)-1,INF,0);
            add(2*i,2*n+1,a[i],0);
            if (i+A+1<=n) add(2*i-1,2*(i+A+1),INF,FA);
            if (i+B+1<=n) add(2*i-1,2*(i+B+1),INF,FB);
        }
    
        while (spfa(0,2*n+1));
        cout<<ans<<endl;
    	return 0;
    }
    
    
  • 相关阅读:
    【36氪收录】观「招商银行」隐私计算布局的思考
    如何用cmake编译
    docker | Ubuntu16.04安装与卸载docker
    通过删除注册表重新获得软件试用期
    k8s | 重启Kubernetes Pod的几种方式
    2021年终总结(一)
    凡是过往、皆为序章20210917PPT分享
    多厂商容器平台开发系统性总结
    VS2022安装.NetFramework4.0目标包的方法
    C# Winform窗体继承过程中,TableLayoutPanel是不支持继承的
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8968934.html
Copyright © 2011-2022 走看看