#include "stdio.h" // 最小費用最大流 poj 2516#include "string.h"
#include "queue"
using namespace std;
#define n 115
#define inf 1000000000
struct node edge[8*n*n];
int store[n];
int n,m,k,ans,idx;
int head[n],dis[n],route[n],mark[n];
int shop[n][n],supply[n][n],cost[n][n];
void init();
void ek(int start,int end);
int spfa(int start,int end);
void adde(int u,int v,int w,int k);
void addedge(int u,int v,int w,int k);
int main()
} for(i=1;i<=m;i++)
}sum = 0; //答案初始化(sum記錄結果)
bool flag=true;
for(tt=1;tt<=k;tt++)
}for(j=1;j<=m;j++)
adde(start,j,0,supply[j][tt]);
for(i=1;i<=n;i++)
while(spfa(start,end))
ek(start,end);
sum += ans;
} if(flag==false)
printf("-1\n");
else
printf("%d\n",sum);
} return 0;
}void init()
void adde(int u,int v,int w,int k) //對其中的一條再加上一條流量為0的迴路
void addedge(int u,int v,int w,int k) //鄰接表建邊
int spfa(int start,int end) //找一條存在流量的最小費用流(存在流量就行)
} }
q.pop();
mark[x] = false; //對出佇列的點的標記還原
} if(dis[end] == inf) return 0;
return 1;
}
void ek(int start,int end)
y = route[end];
while(y!=-1)
}
最小費用最大流poj2516
include include include include include include include include include define ll long long define inf 0x3f3f3f3f using namespace std const int n 1e3 ...
poj2516(最小費用最大流模版)
首先就這題而言,各k互不影響,可以分開來算,累加即可 對於構圖來說,以後可以源點s 0,匯點t n m,其中一組點是1 n,另一組n 1 n m,注意可以這樣構圖 對於最小費用最大流,要用spfa來做最短路徑,只需記錄路徑即可 include include include include incl...
poj 2516 最小費用流
1 include 2 include 3 include 4 include 5 include 6 include 7 using namespace std 89 define inf 0x3f3f3f3f 1011 int supply 55 demand 55 某種商品的提供量和需求量 1...