Interesting Housing Problem 【HDU - 2426】【KM算法】
HDU - 2426 经过这一道题,对KM有了更多的理解,首先,KM是一个完美匹配,也就是说,对于一个二分图的两边,X边和Y边,我们应当保证X边的点数与Y边的点数的数量是相等的,当然,我们以“少补”的策略来解决这个问题的。 然后,就是这道题了。 每一个人都不想去住自己不喜欢的房子,没有一个人会住自己不喜欢的房子,所以一旦有人要住自己不喜欢的房子,或者房子的数量不够的话,就是输出“-1”了。其次的话,输出最大权。 #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <limits> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #define lowbit(x) ( x&(-x) ) #define pi 3.141592653589793 #define e 2.718281828459045 #define INF 0x3f3f3f3f #define HalF (l + r)