Title Description
Transmission Door
Exercises
For each product, S->i,ci,inf
For employees J can produce products I,i->j,inf,ci
For each employee I and the enumeration to SI=J,I->T,T[I][J]-T[I][J-1],W[I][J]
Code
#include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespace STD;#define LL Long LongConst intmax_n= -;Const intmax_n=max_n*Ten+2;Const intmax_m=max_n* -;Const intmax_e=max_m*2;ConstLL inf=1e18; LL M,n,sum,n,mincost; LL A[max_n][max_n],s[max_n],ss[max_n],c[max_n],t[max_n][max_n],w[max_n][max_n]; LL Tot,point[max_n],nxt[max_e],v[max_e],remain[max_e],c[max_e]; LL Dis[max_n],last[max_n];BOOLVis[max_n]; queue <LL>Qinline voidAddedge (LL x,ll y,ll cap,ll z) {++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; remain[tot]=cap; c[tot]=z; ++tot; Nxt[tot]=point[y]; Point[y]=tot; V[tot]=x; remain[tot]=0; C[tot]=-z;}inlinell Addflow (ll S,ll t) {ll now=t,ans=inf; while(now!=s) {ans=min (Ans,remain[last[now]); now=v[last[now]^1]; } now=t; while(now!=s) {Remain[last[now]]-=ans; remain[last[now]^1]+=ans; now=v[last[now]^1]; }returnAns;}inline BOOLBFS (LL s,ll t) { for(LL i=1; i<=n;++i) Dis[i]=inf; dis[s]=0;memset(Vis,0,sizeof(VIS)); vis[s]=true; while(!q.empty ()) Q.pop (); Q.push (s); while(!q.empty ()) {LL now=q.front (); Q.pop (); vis[now]=false; for(LL i=point[now];i!=-1; I=nxt[i])if(Dis[v[i]]>dis[now]+c[i]&&remain[i]) {Dis[v[i]]=dis[now]+c[i]; Last[v[i]]=i;if(!vis[v[i]]) {vis[v[i]]=true; Q.push (V[i]); } } }if(Dis[t]==inf)return false; LL Flow=addflow (s,t); MINCOST+=FLOW*DIS[T];return true;}inline voidMincost_flow (LL s,ll t) { while(BFS (S,t));}intMain () {tot=-1;memset(point,-1,sizeof(point));memset(nxt,-1,sizeof(NXT));scanf("%lld%lld", &m,&n); for(LL i=1; i<=n;++i)scanf("%lld", &c[i]); for(LL i=1; i<=m;++i) for(LL j=1; j<=n;++j)scanf("%lld", &a[i][j]); for(LL i=1; i<=m;++i) {scanf("%lld", &s[i]); for(LL j=1; j<=s[i];++j)scanf("%lld", &t[i][j]); t[i][s[i]+1]=inf; for(LL j=1; j<=s[i]+1; ++j)scanf("%lld", &w[i][j]); } n=n+m+2; for(LL i=1; i<=n;++i) Addedge (1,1+i,c[i],0); for(LL i=1; i<=n;++i) for(LL j=1; j<=m;++j)if(A[j][i]) Addedge (1+i,1+n+j,inf,0); for(LL i=1; i<=m;++i) for(LL j=1; j<=s[i]+1; ++j) Addedge (1+n+i,n,t[i][j]-t[i][j-1],W[I][J]); Mincost_flow (1, N);printf("%lld\n", mincost);}
Summarize
Just started reading the wrong question. 233
[BZOJ2245] [SDOI2011] organization of work (cost flow)