• bzoj1221: [HNOI2001] 软件开发


    挖坑。我的那种建图方式应该也是合理的。然后连样例都过不了。果断意识到应该为神奇建图法。。。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    #define rep(i,n) for(int i=1;i<=n;i++)
    #define clr(x,c) memset(x,c,sizeof(x))
    #define op() clr(head,0);pt=edges;
    #define qwq(x) for(edge *o=head[x];o;o=o->next)
    int read(){
    	int x=0;char c=getchar();
    	while(!isdigit(c)) c=getchar();
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x;
    }
    const int nmax=2005;
    const int maxn=2000000;
    const int inf=0x7f7f7f7f;
    struct edge{
    	int to,cap,cost;edge *next,*rev;
    };
    edge edges[maxn],*pt,*head[nmax],*p[nmax];
    int d[nmax],a[nmax];bool inq[nmax];
    queue<int>q;
    void add(int u,int v,int d,int w){
    	pt->to=v;pt->cap=d;pt->cost=w;pt->next=head[u];head[u]=pt++;
    }
    void adde(int u,int v,int d,int w){
    	add(u,v,d,w);add(v,u,0,-w);head[u]->rev=head[v];head[v]->rev=head[u];
    }
    int mincost(int s,int t){
    	int cost=0;
    	while(1){
    		clr(d,0x7f);d[s]=0;clr(inq,0);inq[s]=1;q.push(s);a[s]=inf;
    		while(!q.empty()){
    			int x=q.front();q.pop();inq[x]=0;
    			qwq(x) if(d[o->to]>d[x]+o->cost&&o->cap>0){
    				int to=o->to;d[to]=d[x]+o->cost;
    				a[to]=min(a[x],o->cap);p[to]=o;
    				if(!inq[to]) q.push(to),inq[to]=1;
    			}
    		}
    		if(d[t]==inf) break;
    		cost+=d[t]*a[t];
    		int x=t;
    		while(x!=s) p[x]->cap-=a[t],p[x]->rev->cap+=a[t],x=p[x]->rev->to;
    	}
    	return cost;
    }
    int main(){
    	op();
    	int n=read(),a=read(),b=read(),f=read(),fa=read(),fb=read(),s=0,t=n+n+1;
    	/*rep(i,n){
    		int tmp=read();adde(s,i,inf,f);adde(n+i,t,tmp,0);adde(i,n+i,inf,0);
    	}
    	rep(i,n-1) adde(n+i,i+1,inf,0);
    	for(int i=1;i+a+1<=n;i++) adde(n+i,i+a+1,inf,fa);
    	for(int i=1;i+b+1<=n;i++) adde(n+i,i+b+1,inf,fb);*/
    	rep(i,n){
    		int tmp=read();adde(s,i,tmp,0);adde(i+n,t,tmp,0);adde(s,i+n,inf,f);
    	}
    	for(int i=1;i+a+1<=n;i++) adde(i,i+n+a+1,inf,fa);
    	for(int i=1;i+b+1<=n;i++) adde(i,i+n+b+1,inf,fb);
    	rep(i,n-1) adde(i,i+1,inf,0);
    	printf("%d
    ",mincost(s,t));
    	return 0;
    }
    

     

    1221: [HNOI2001] 软件开发

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 1255  Solved: 700
    [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

     

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    Linux基础命令练习题答案7.9
    Linux基础练习题7.9
    Linux基础练习题答案7.8
    Linux基础练习题7.8
    12 drf精华总结
    11 drf(RBAC)基于角色的权限控制
    10 drfJWT认证
    09 drf自动生成接口文档
    08 drf分页器
    Python 3.9正式版,新特性提前一睹为快
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5661801.html
Copyright © 2020-2023  润新知