裸费用流,要注意的是当天供应的东西不一定要从仓库里拿,所以S限制的容量应该是i'-(i+1)的
数据那么弱,暴力或许过得去?
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(int i=l;i<=r;i++) 3 #define dec(i,l,r) for(int i=l;i>=r;i--) 4 #define link(x) for(edge *j=h[x];j;j=j->next) 5 #define mem(a) memset(a,0,sizeof(a)) 6 #define inf 1e9 7 #define ll long long 8 #define succ(x) (1<<x) 9 #define NM 150 10 #define nm 10000 11 using namespace std; 12 int read(){ 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*10+ch-'0',ch=getchar(); 16 return x*f; 17 } 18 struct edge{ 19 int t,v,w; 20 edge *next,*rev; 21 }e[nm],*h[NM],*o=e,*p[NM]; 22 void _add(int x,int y,int w,int v){ 23 o++;o->t=y;o->v=v;o->w=w;o->next=h[x];h[x]=o; 24 } 25 void add(int x,int y,int w,int v){ 26 _add(x,y,w,v);_add(y,x,0,-v); 27 h[x]->rev=h[y];h[y]->rev=h[x]; 28 } 29 int n,m,V,tot,d[NM],b[NM],ans; 30 bool v[NM]; 31 queue<int >q; 32 int spfa(){ 33 mem(v);mem(b); 34 inc(i,0,n)d[i]=inf; 35 v[0]++;q.push(0);d[0]=0;b[0]=inf; 36 while(!q.empty()){ 37 int t=q.front();q.pop();v[t]=false; 38 link(t) 39 if(j->w&&d[j->t]>d[t]+j->v){ 40 d[j->t]=d[t]+j->v; 41 p[j->t]=j;b[j->t]=min(b[t],j->w); 42 if(!v[j->t])v[j->t]++,q.push(j->t); 43 } 44 } 45 return d[n]<inf; 46 } 47 int main(){ 48 freopen("data.in","r",stdin); 49 n=read();m=read();V=read();tot=2*n+1; 50 inc(i,1,n)add(i+n,tot,read(),0); 51 inc(i,1,n)add(0,i,inf,read()); 52 inc(i,1,n)add(i,i+n,inf,0); 53 inc(i,1,n-1)add(i+n,i+1,V,m); 54 n=tot; 55 while(spfa()){ 56 ans+=d[n]*b[n]; 57 for(int x=n;x;x=p[x]->rev->t) 58 p[x]->w-=b[n],p[x]->rev->w+=b[n]; 59 } 60 printf("%d\n",ans); 61 return 0; 62 }