Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transparencies on one big heap. Before giving the talk, he has to sort the slides. Being a kind of minima…
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transparencies on one big heap. Before giving the talk, he has to sort the slides. Being a kind of minima…
题目描述: Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transparencies on one big heap. Before giving the talk, he has to sort the slides. Being a kind of minimalist,…
题意 给你n个幻灯片,每个幻灯片有个数字编号1~n,现在给每个幻灯片用A~Z进行编号,在该幻灯片范围内的数字都可能是该幻灯片的数字编号.问有多少个幻灯片的数字和字母确定的. 思路 确定幻灯片的数字就是求完美匹配也就是最大匹配,而题目要求的边就是匹配的关键边,也叫必须边,即任意一个最大匹配一定要包含这条边. 关键边求法:先求一遍最大匹配,然后枚举删去匹配边,看之后的最大匹配是否减小,如果减小则该边是匹配关键边. 这让我想起了寻找关键割边:如果一个割边增加流量后整个最大流增加则该割边是关键割边.呵呵…
[题目链接] http://poj.org/problem?id=1486 [题目大意] 给出每张幻灯片的上下左右坐标,每张幻灯片的页码一定标在这张幻灯片上, 现在问你有没有办法唯一鉴别出一些幻灯片 [题解] 我们先求一遍匹配,然后对于匹配的边进行删去后再匹配, 如果匹配数量发生变化,则说明这条边不是完美匹配, 测试每一条边之后,我们就能得到完美匹配的边,就是答案. [代码] #include <cstdio> #include <cstring> using namespace…
Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5390   Accepted: 2095 Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transpa…
题意: 给出一个有向带权图,找到若干个圈,使得每个点恰好属于一个圈.而且这些圈所有边的权值之和最小. 分析: 每个点恰好属于一个有向圈 就等价于 每个点都有唯一后继. 所以把每个点i拆成两个点,Xi 和 Yi ,然后求二分图最小权完美匹配(流量为n也就是满载时,就是完美匹配). #include <bits/stdc++.h> using namespace std; + ; ; struct Edge { int from, to, cap, flow, cost; Edge(int u,…
今天也大致学了下KM算法,用于求二分图匹配的最佳匹配. 何为最佳?我们能用匈牙利算法对二分图进行最大匹配,但匹配的方式不唯一,如果我们假设每条边有权值,那么一定会存在一个最大权值的匹配情况,但对于KM算法的话这个情况有点特殊,这个匹配情况是要在完全匹配(就是各个点都能一一对应另一个点)情况下的前提. 自然,KM算法跟匈牙利算法有相似之处. 其算法步骤如下: 1.用邻接矩阵(或其他方法也行啦)来储存图,注意:如果只是想求最大权值匹配而不要求是完全匹配的话,请把各个不相连的边的权值设置为0. 2.运…
恰好属于一个圈,那等价与每个点有唯一的前驱和后继,这让人想到了二分图, 把一个点拆开,点的前驱作为S集和点的后继作为T集,然后连边,跑二分图最小权完美匹配. 写的费用流..最大权完美匹配KM算法没看懂 #include<bits/stdc++.h> using namespace std; +; struct Edge { int v,cap,cost,nxt; }; vector<Edge> edges; #define PB push_back int head[maxn];…
二分图网络流做法 (1)最大基数匹配.源点到每一个X节点连一条容量为1的弧, 每一个Y节点连一条容量为1的弧, 然后每条有向 边连一条弧, 容量为1, 然后跑一遍最大流即可, 最大流即是最大匹配对数 (2)最小(大)权完美匹配(每个点都被匹配到).和最大基数匹配类似, 只是有向边的权值就是费用, 其余弧费用为0. 跑一遍最小费用流.最后要判断从s出发的弧是否满载, 不是则不能完美匹配.如果求最大权那么费用设为负的就ok. 这道题目每一个点恰好在一个圈内, 也就是说每一个点只有唯一的后继.反过来,…