poj2516(最小費用最大流模版)

2021-07-14 00:00:25 字數 1234 閱讀 1803

首先就這題而言,各k互不影響,可以分開來算,累加即可

對於構圖來說,以後可以源點s=0,匯點t=n+m,其中一組點是1~n,另一組n+1~n+m,注意可以這樣構圖

對於最小費用最大流,要用spfa來做最短路徑,只需記錄路徑即可

#include#include#include#include#include#define n 130

using namespace std;

const int inf=0x3f3f3f3f;

int n,m,k,offer[n][n],need[n][n],map[n][n],cost[n][n],sumn[n],sumo[n],pre[n],s,t;

bool spfa()

; int dis[n];

memset(dis,inf,sizeof(dis));//對了,不能int dis={inf}這樣付初值,這樣絕對不可以!!!!!!!!!!!!!

queueq;

vis[s]=true;

dis[s]=0;

q.push(s);

while (!q.empty())

}vis[u]=false;

}/spfa,

if (dis[t]==inf) return false;else return true;//判斷是否有增廣路,然後返回即可。

}int work()

return ans;//返回最小費用!

}int main()

{ while (scanf("%d%d%d",&n,&m,&k))

{ memset(sumn,0,sizeof(sumn));

memset(sumo,0,sizeof(sumo));

memset(need,0,sizeof(need));

memset(offer,0,sizeof(offer));

if (n==0) break;

int sign=0;

for (int i=1;i<=n;i++)

for (int j=1;j<=k;j++) scanf("%d",&need[i][j]),sumn[j]+=need[i][j];

for (int i=1;i<=m;i++)

for (int j=1;j<=k;j++) scanf("%d",&offer[i][j]),sumo[j]+=offer[i][j];

for (int j=1;j<=k;j++)

if (sumo[j]

最小費用最大流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 最小費用最大流

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 stor...

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...