探索flutter框架开发的app在移动应用市场的潜力与挑战
577
2022-08-26
POJ 2516 Minimum Cost (最小费用最大流)
Description
Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area there are N shopkeepers (marked from 1 to N) which stocks goods from him.Dearboy has M supply places (marked from 1 to M), each provides K different kinds of goods (marked from 1 to K). Once shopkeepers order goods, Dearboy should arrange which supply place provide how much amount of goods to shopkeepers to cut down the total cost of transport. It’s known that the cost to transport one unit goods for different kinds from different supply places to different shopkeepers may be different. Given each supply places’ storage of K kinds of goods, N shopkeepers’ order of K kinds of goods and the cost to transport goods for different kinds from different supply places to different shopkeepers, you should tell how to arrange the goods supply to minimize the total cost of transport.
Input
The input consists of multiple test cases. The first line of each test case contains three integers N, M, K (0 < N, M, K < 50), which are described above. The next N lines give the shopkeepers’ orders, with each line containing K integers (there integers are belong to [0, 3]), which represents the amount of goods each shopkeeper needs. The next M lines give the supply places’ storage, with each line containing K integers (there integers are also belong to [0, 3]), which represents the amount of goods stored in that supply place. Then come K integer matrices (each with the size N * M), the integer (this integer is belong to (0, 100)) at the i-th row, j-th column in the k-th matrix represents the cost to transport one unit of k-th goods from the j-th supply place to the i-th shopkeeper. The input is terminated with three “0”s. This test case should not be processed.
Output
For each test case, if Dearboy can satisfy all the needs of all the shopkeepers, print in one line an integer, which is the minimum cost; otherwise just output “-1”.
Sample Input
1 3 3 1 1 10 1 11 2 21 0 11 2 31 1 12 1 11 1 132200 0 0
Sample Output
4-1
题意
有n个店主,k个物品,m个供应商,求满足店主需求所需要的最小花费。
思路
分析题目可以得出,k个物品之间是没有关系的,因为它们之间的独立,所以我们可以将这k个物品单独计算。
创建源点与汇点,从源点到供应商之间的一条容量为供应量费用为0的边可以看作是供应商的供应情况,然后从店主到汇点之间一条容量为需求量费用为0的边可以看作是店主的需求情况,至于供应商与店主之间也有相应的边,它的容量可以是无限大,然后需要的花费为实际花费,此时从源点到汇点之间的最小费用即为供应这一种物品所需要花费的最小费用。
当供应量不足需求的时候,输出 -1 。
AC 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~