博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2112 Optimal Milking 二分图多重匹配+floyd+二分
阅读量:3905 次
发布时间:2019-05-23

本文共 2612 字,大约阅读时间需要 8 分钟。

题目:

FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 <= C <= 200) cows. A set of paths of various lengths runs among the cows and the milking machines. The milking machine locations are named by ID numbers 1..K; the cow locations are named by ID numbers K+1..K+C.

Each milking point can "process" at most M (1 <= M <= 15) cows each day.
Write a program to find an assignment for each cow to some milking machine so that the distance the furthest-walking cow travels is minimized (and, of course, the milking machines are not overutilized). At least one legal assignment is possible for all input data sets. Cows can traverse several paths on the way to their milking machine.

Input

* Line 1: A single line with three space-separated integers: K, C, and M.

* Lines 2.. ...: Each of these K+C lines of K+C space-separated integers describes the distances between pairs of various entities. The input forms a symmetric matrix. Line 2 tells the distances from milking machine 1 to each of the other entities; line 3 tells the distances from machine 2 to each of the other entities, and so on. Distances of entities directly connected by a path are positive integers no larger than 200. Entities not directly connected by a path have a distance of 0. The distance from an entity to itself (i.e., all numbers on the diagonal) is also given as 0. To keep the input lines of reasonable length, when K+C > 15, a row is broken into successive lines of 15 numbers and a potentially shorter line to finish up a row. Each new row begins on its own line.

Output

A single line with a single integer that is the minimum possible total distance for the furthest walking cow.

Sample Input

2 3 20 3 2 1 13 0 3 2 02 3 0 1 01 2 1 0 21 0 0 2 0

Sample Output

2

思路:

先将各个点的最短路径求出来。

然后建立牛和机器的图。

然后根据二分的值来建另一张图,然后跑多重匹配。

代码如下:

#include 
#include
#include
#include
using namespace std;const int maxn=250;const int INF=0x3f3f3f3f;int a[maxn][maxn];int head[maxn];int k,c,m;int match[maxn][maxn];int num[maxn];int vis[maxn];int ma[maxn][maxn];struct edge{ int len; int to; int next;}edge[maxn*maxn];void add (int id,int u,int v,int len){ edge[id].to=v; edge[id].next=head[u]; edge[id].len=len; head[u]=id;}bool Find(int x,int mid){ for (int i=1;i<=k;i++) { if(!vis[i]&&ma[x][i]) { vis[i]=1; if(num[i]
a[i][m]+a[m][j]) { a[i][j]=a[i][m]+a[m][j]; } } } } int l=0,r=INF; while(l

 

转载地址:http://dzoen.baihongyu.com/

你可能感兴趣的文章
Net Remoting Singleton and Singlecall 区别
查看>>
2016年安大校赛(补题)
查看>>
BESTCODER ROUND92 1001.Skip the Class
查看>>
POJ 1661 Help Jimmy
查看>>
百练OJ 2755 神奇的口袋(递归+递推)
查看>>
HDU 1003 Max Sum
查看>>
Code Vs 1014 装箱
查看>>
循环队列,队链的实现
查看>>
HDU 2602 Bone Collector (01背包)
查看>>
POJ 1837 Blance (01背包)
查看>>
HDU 2456 饭卡 (01背包)
查看>>
HDU 1559 最大子矩阵
查看>>
Open Judge 4010 :2011
查看>>
百练OJ-2815 城堡问题【DFS】
查看>>
CODE[VS] 1025 选菜 【背包】
查看>>
POJ 1724 ROADS【DFS+剪枝】
查看>>
AOJ 847 整数拆段
查看>>
AOJ 848 分数拆分
查看>>
UVA 133 The Dole Queue 【约瑟夫环】
查看>>
XDOJ 1208 B.笑爷买房 【DFS】
查看>>