网络流/费用流

说是这题跟餐巾计划一模一样……但我没做过啊……so sad


二分图建模是很好想的,但是要控制流量跟用了的毛巾一样多……oh my god

事实上对于每一天我们无论如何都是要消耗n[i]条毛巾的,那么我们可以直接连边 i->T 容量为n[i],费用为0。

那么只需要考虑这n[i]条毛巾是哪来的了= =:1.买来 2.快洗 3.慢洗 。快洗来的肯定是从i-a-1那天来的……所以我们连S->i 容量 n[i]……

TAT感觉说不清了……


……嗯……嗯……这么建图的结果就是:如果是洗过的毛巾就会从S流到 i-a(b)-1那天的x部结点,再流到第 i 天的y部结点,反正就有点像星际竞速那题一样,分开处理了!相当于对每天单独考虑?了毛巾来源

【BZOJ】【1221】【HNOI2001】软件开发_费用流【BZOJ】【1221】【HNOI2001】软件开发_#include_02

1 /**************************************************************
2 Problem: 1221
3 User: Tunix
4 Language: C++
5 Result: Accepted
6 Time:1396 ms
7 Memory:5988 kb
8 ****************************************************************/
9
10 //BZOJ 1221
11 #include<vector>
12 #include<cstdio>
13 #include<cstring>
14 #include<cstdlib>
15 #include<iostream>
16 #include<algorithm>
17 #define rep(i,n) for(int i=0;i<n;++i)
18 #define F(i,j,n) for(int i=j;i<=n;++i)
19 #define D(i,j,n) for(int i=j;i>=n;--i)
20 #define pb push_back
21 using namespace std;
22 inline int getint(){
23 int v=0,sign=1; char ch=getchar();
24 while(ch<'0'||ch>'9'){ if (ch=='-') sign=-1; ch=getchar();}
25 while(ch>='0'&&ch<='9'){ v=v*10+ch-'0'; ch=getchar();}
26 return v*sign;
27 }
28 const int N=2100,M=200000,INF=~0u>>2;
29 typedef long long LL;
30 /******************tamplate*********************/
31 int n,f,a,b,fa,fb,ans;
32 struct edge{int from,to,v,c;};
33 struct Net{
34 edge E[M];
35 int head[N],next[M],cnt;
36 void ins(int x,int y,int z,int c){
37 E[++cnt]=(edge){x,y,z,c};
38 next[cnt]=head[x]; head[x]=cnt;
39 }
40 void add(int x,int y,int z,int c){
41 ins(x,y,z,c); ins(y,x,0,-c);
42 }
43 int from[N],Q[M],d[N],S,T,ed;
44 bool inq[N],sign;
45 bool spfa(){
46 int l=0,r=-1;
47 F(i,1,T) d[i]=INF;
48 d[S]=0; Q[++r]=S; inq[S]=1;
49 while(l<=r){
50 int x=Q[l++];
51 inq[x]=0;
52 for(int i=head[x];i;i=next[i])
53 if(E[i].v>0 && d[x]+E[i].c<d[E[i].to]){
54 d[E[i].to]=d[x]+E[i].c;
55 from[E[i].to]=i;
56 if (!inq[E[i].to]){
57 Q[++r]=E[i].to;
58 inq[E[i].to]=1;
59 }
60 }
61 }
62 return d[T]!=INF;
63 }
64 void mcf(){
65 int x=INF;
66 for(int i=from[T];i;i=from[E[i].from])
67 x=min(x,E[i].v);
68 for(int i=from[T];i;i=from[E[i].from]){
69 E[i].v-=x;
70 E[i^1].v+=x;
71 }
72 ans+=x*d[T];
73 }
74 void init(){
75 n=getint(); a=getint(); b=getint();
76 f=getint();fa=getint();fb=getint();
77 cnt=1; S=0; T=n+n+1;
78 int x;
79 F(i,1,n){
80 x=getint();
81 add(S,i+n,INF,f);
82 add(S,i,x,0); add(i+n,T,x,0);
83 if (i<n) add(i,i+1,INF,0);
84 if (i+a+1<=n) add(i,i+n+a+1,INF,fa);
85 if (i+b+1<=n) add(i,i+n+b+1,INF,fb);
86 }
87 while(spfa()) mcf();
88 printf("%d\n",ans);
89 }
90 }G1;
91
92 int main(){
93 #ifndef ONLINE_JUDGE
94 freopen("1221.in","r",stdin);
95 freopen("1221.out","w",stdout);
96 #endif
97 G1.init();
98 return 0;
99 }

View Code



1221: [HNOI2001] 软件开发

Time Limit: 10 Sec Memory Limit: 162 MB

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