POJ 2516 基礎費用流

2021-06-23 03:40:18 字數 1832 閱讀 3006

題意

有n個顧客,m個**商,k種貨物,給你顧客對於每種貨物的要求個數,和**商對於每種貨物的現有量,以及**每種貨物的時候**商和顧客之間的運輸單價,問你滿足所有顧客的前提下的最小運輸費用是多少。

思路:

滿足所有顧客的前提下的最小花費,很容易就想到了費用流,但是做這個題目有個小竅門,如果不想的話很可能把每個點拆成三個點,然後在去跑,但是這樣感覺寫著麻煩,ac肯定沒問題,但是仔細想想,每種貨物之間是沒有任何關係的,那麼我們何不直接每種貨物都跑一遍費用流,這樣寫起來很簡單,思路也清晰,建圖的話應該不用說了吧,水建圖。

#include

#include

#include

#define n 50+5

#define n_node 120

#define n_edge 6000

#define inf 100000000

using

namespace std;

typedef

struct

star;

star e[n_edge];

int list[n_node]

,tot;

int s_x[n_node]

,mer[n_edge];

int need[n][n]

,supply[n][n];

void

add(

int a ,

int b ,

int c ,

int d)

bool

spfa

(int s ,

int t ,

int n)

; s_x[s]=0

,mark[s]=1

; queue<

int>q;

q.push

(s);

memset

(mer ,

255,

sizeof

(mer));

while

(!q.

empty

())}}}

return mer[t]!=-

1;}int

m_c_flow

(int s ,

int t ,

int n ,

int sum)

maxflow += minflow;}if

(maxflow != sum)

return-1

;return mincost;

}int

main

()if

(mk)

continue

;int sum =0;

for(i =

1;i <= n ;i ++)

for(i =

1;i <= m ;i ++)

add(i + n ,n + m +1,

0,supply[i][ii]);

int tmp =

m_c_flow(0

,n + m +

1,n + m +

1,sum);

if(tmp ==-1

) mk =1;

else ans += tmp;

} mk ?

puts

("-1"):

printf

("%d\n"

,ans);

}return0;

}

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

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