随笔分类 -  最小费用最大流

摘要:#include #include #include #include #define mul(a) (a)*(a)using namespace std;const int Maxn = 210;const int Maxm = 100010;const int inf = 0x3f3f3f3f;struct ZKW_flow{ int st, ed, ecnt, n; int head[Maxn]; int cap[Maxm], cost[Maxm], to[Maxm], next[Maxm]; void init(){ memset(head, -1... 阅读全文
posted @ 2013-09-17 18:02 fangguo 阅读(290) 评论(0) 推荐(0)
摘要:思路:这题我在下午重现的时候就用的费用流做,可是各种悲催的超时,只是我一开始的那种建图方式多了一个二分查找。戏剧性的是,求距离的返回值写成int型了,CodeBlock编译器又没有警告,然后就WA啊WA,AC率一下就被拉低了。当然,对每种工人分别建图是不变的,因为每种工人互不影响。后来想到了一个较好的建图方式,将每个点拆成3个点,i,i+n,i+2*n。1号点就是仓库,也就是超级源点,3*n+1号点为超级汇点。由1号点想每个i建一条流量为ty[i][j],费用为1的边。表示每次增加流量,人数就增加。由i向i+2*n建一条流量为ty[i][j],费用为0的边。由i+2*n向汇点建一条流量为ty[ 阅读全文
posted @ 2013-08-24 23:26 fangguo 阅读(848) 评论(0) 推荐(0)
摘要:思路:主要就是要把一个每个城市拆为两个点,建一条容量为1,费用为-inf的边,保证每个城市都会被遍历。/*最小费用最大流*/#include#include#include#include#includeusing namespace std;const int Maxn = 1010;const int inf = 1000010;struct Edge{ int v; int val; int cost; int next;}edge[Maxn*100];int head[Maxn],n,g[Maxn][Maxn],m,k;int e;int pre[Maxn], ... 阅读全文
posted @ 2013-08-17 16:50 fangguo 阅读(138) 评论(0) 推荐(0)
摘要:就是最基本的二分图最优匹配,将每个人向每个房子建一条边,权值就是他们manhattan距离。然后对所有权值取反,求一次最大二分图最优匹配,在将结果取反就行了。#include#include#include#include#define Maxn 110using namespace std;int n;//点的数目int lx[Maxn],ly[Maxn]; //顶点标号int weight[Maxn][Maxn];// 边的权值int slack[Maxn];// Y(i)的松弛函数int sx[Maxn],sy[Maxn]; //标记X,Y中的顶点是否在交错路径上int match[Ma 阅读全文
posted @ 2013-07-17 11:33 fangguo 阅读(494) 评论(0) 推荐(0)