# 洛谷2050 BZOJ2897美食节题解

BZ链接

# include<iostream>
# include<cstdio>
# include<algorithm>
# include<cmath>
# include<cstring>
# include<queue>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mn = 100005;
int c[45][105],p[45];
struct edge{int to,next,flow,cost;};
edge e[3000005];
void add(int x,int y,int z,int k)
{
//printf("%d %d %d %d\n",x,y,z,k);
e[++edge_max].to=y;
e[edge_max].flow=z;
e[edge_max].cost=k;
}
int n,m,sum;
int dis[mn],pe[mn],pv[mn],ansc,ansf;
bool vis[mn];
queue<int> q;
bool spfa(int x,int y)
{
memset(dis,0x3f,sizeof(dis));
dis[x]=0;
q.push(x);
while(!q.empty())
{
int u=q.front();
vis[u]=0;
q.pop();
{
if(e[i].flow>0 && e[i].cost+dis[u]<dis[e[i].to])
{
dis[e[i].to]=dis[u]+e[i].cost;
pv[e[i].to]=u;
pe[e[i].to]=i;
if(!vis[e[i].to])
{
vis[e[i].to]=1;
q.push(e[i].to);
}
}
}
}
//for(int i=0;i<=y;i++)
//printf("%d ",dis[y]);
return dis[y]<inf;
}
void max_flow(int x,int y)
{
int kflow,a,b;//a表示厨师编号
while(spfa(x,y))
{
//printf("%d %d\n",ansc,ansf);
kflow=inf;
for(int i=y;i!=x;i=pv[i])
kflow=min(kflow,e[pe[i]].flow);
a=(pv[y]-1)/sum+1;
b=pv[y]%sum+1;
ansf+=kflow;
ansc+=kflow*dis[y];
for(int i=y;i!=x;i=pv[i])
{
e[pe[i]].flow-=kflow;
e[pe[i]^1].flow+=kflow;
//ansc+=kflow*e[pe[i]].cost;
}
for(int i=1;i<=n;i++)
}
}
int main()
{
int st=0;
//freopen("testdata.in","r",stdin);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]),sum+=p[i];
int en=sum*m+n+1;
// printf("%d\n",en);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&c[i][j]);
for(int i=1;i<=n;i++)
}