标签:
#include<cstdio> #include<cmath> #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<queue> using namespace std; const int maxn=2100,maxm=110000,inf=0x7fffffff; int n,m,p,f,ss,tt,a,b,s,t,mincost,tot=1,head[maxn],d[maxn],from[maxm*2]; queue<int> q; bool v[maxn]; struct node{ int from,go,v,c,next; }e[maxm*2]; inline int read(){ int x=0;char ch=getchar(); while (ch<‘0‘ || ch>‘9‘) ch=getchar(); while (ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x; } inline void addedge(int x,int y,int v,int c){ e[++tot]=(node){x,y,v,c,head[x]};head[x]=tot; e[++tot]=(node){y,x,0,-c,head[y]};head[y]=tot; } bool spfa(){ for (int i=s;i<=t;i++) v[i]=0,d[i]=inf; q.push(s);d[s]=0;v[s]=1; while (!q.empty()){ int x=q.front();q.pop();v[x]=0; for (int i=head[x],y;i;i=e[i].next){ if (e[i].v && d[x]+e[i].c<d[y=e[i].go]){ d[y]=d[x]+e[i].c;from[y]=i; if (!v[y]) v[y]=1,q.push(y); } } } return d[t]!=inf; } void mcf(){ mincost=0; while(spfa()){ int tmp=inf; for (int i=from[t];i;i=from[e[i].from]) tmp=min(tmp,e[i].v); mincost+=tmp*d[t]; for (int i=from[t];i;i=from[e[i].from]) e[i].v-=tmp,e[i^1].v+=tmp; } } int main(){ scanf("%d%d%d%d%d%d",&n,&p,&m,&f,&tt,&ss); s=0;t=n+n+1; for (int i=1;i<=n;i++){ a=read(); addedge(s,i,a,0); addedge(n+i,t,a,0); addedge(s,n+i,inf,p); if (i<n) addedge(i,i+1,inf,0); if (i+m<=n) addedge(i,n+m+i,inf,f); if (i+tt<=n) addedge(i,n+i+tt,inf,ss); } mcf(); printf("%d\n",mincost); }
标签:
原文地址:http://www.cnblogs.com/fqqq/p/5239950.html