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


    [HNOI2001] 软件开发

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 1938  Solved: 1118
    [Submit][Status][Discuss]

    Description

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

    Input

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

    Output

    最少费用

    Sample Input

    4 1 2 3 2 1
    8 2 1 6

    Sample Output

    38

    HINT

     

    题解:这个和网络流24题里的餐巾纸那道题一样的,有一个

       显然的贪心,没必要多买,然后

     
      1 #include<cstring>
      2 #include<cstdio>
      3 #include<algorithm>
      4 #include<iostream>
      5 #include<cmath>
      6 #include<queue>
      7 
      8 #define N 1007
      9 #define inf 1000000007
     10 using namespace std;
     11 inline int read()
     12 {
     13     int x=0,f=1;char ch=getchar();
     14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
     15     while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
     16     return x*f;
     17 }
     18 
     19 int n,a,b,f,fa,fb,S,T;
     20 bool boo[N<<2];
     21 int dis[N<<2];
     22 int cnt=1,hed[N<<2],nxt[N<<4],rea[N<<4],val[N<<4],fee[N<<4];
     23 struct Node
     24 {
     25     int e,fa;
     26     void init()
     27     {
     28         e=fa=-1;
     29     }
     30 }e[N<<2];
     31 
     32 void add(int u,int v,int z,int w)
     33 {
     34     nxt[++cnt]=hed[u];
     35     hed[u]=cnt;
     36     rea[cnt]=v;
     37     val[cnt]=z;
     38     fee[cnt]=w;
     39 }
     40 void add_two_way(int u,int v,int z,int w)
     41 {
     42     add(u,v,z,w);
     43     add(v,u,0,-w);
     44 }
     45 bool Spfa()
     46 {
     47     for (int i=S;i<=T;i++)
     48         dis[i]=inf,e[i].init(),boo[i]=false;
     49     queue<int>q;
     50     q.push(S);boo[S]=true,dis[S]=0;
     51     while(!q.empty())
     52     {
     53         int u=q.front();q.pop();
     54         for (int i=hed[u];i!=-1;i=nxt[i])
     55         {
     56             int v=rea[i],cost=fee[i];
     57             if (dis[v]>dis[u]+cost&&val[i]>0)
     58             {
     59                 dis[v]=dis[u]+cost;
     60                 e[v].fa=u,e[v].e=i;
     61                 if (!boo[v])
     62                 {
     63                     boo[v]=true;
     64                     q.push(v);
     65                 }
     66             }
     67         }
     68         boo[u]=false;
     69     }
     70     if (dis[T]!=inf) return true;
     71     else return false;
     72 }
     73 int mfmc()
     74 {
     75     int ans=0;
     76     while(Spfa())
     77     {
     78         int x=inf;
     79         for (int i=T;e[i].fa!=-1;i=e[i].fa)
     80             x=min(x,val[e[i].e]);
     81         ans+=dis[T]*x;
     82         for (int i=T;e[i].fa!=-1;i=e[i].fa)
     83             val[e[i].e]-=x,val[e[i].e^1]+=x;
     84     }
     85     return ans;
     86 }
     87 int main()
     88 {
     89     memset(hed,-1,sizeof(hed));
     90     n=read(),a=read(),b=read(),f=read(),fa=read(),fb=read();
     91     S=0,T=n*2+1;
     92     for (int i=1;i<=n;i++)
     93     {
     94         if (i+a+1<=n) add_two_way(i,i+n+a+1,inf,fa);
     95         if (i+b+1<=n) add_two_way(i,i+n+b+1,inf,fb);
     96         if (i+1<=n) add_two_way(i,i+1,inf,0);
     97     }
     98     for (int i=1;i<=n;i++)
     99     {
    100         int x=read();
    101         add_two_way(S,i,x,0);
    102         add_two_way(S,i+n,x,f);
    103         add_two_way(i+n,T,x,0);
    104     }
    105     printf("%d
    ",mfmc());
    106 }
  • 相关阅读:
    VC C运行时库(CRTL)的几个版本及选用
    gtest的安装和测试[good]
    【nginx】上传文件error报413 Request Entity Too Large
    mysql proxysql的简单部署读写分离
    python入门之进程与线程
    mysql主从复制之同步部分库表
    python入门之paramiko模块
    python入门之socket代码练习
    k8s的ingress使用
    【Jenkins】自动触发部署之插件Generic Webhook Trigger Plugin
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8835066.html
Copyright © 2020-2023  润新知