雕刻时光

just do it……nothing impossible
随笔 - 547, 文章 - 0, 评论 - 82, 阅读 - 86万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

随笔分类 -  二分图专辑

摘要:做了一点,差不多总结下最大二分匹配有这么几种题目最大匹配:匈牙利算法最小点覆盖:等于最大匹配数最大独立集:顶点数-最大匹配数最小边覆盖:顶点数-最大匹配数(最小边覆盖有边不可相交,边可以相交,边可以相交时可以用floyd判断图的连通性,有环存在要缩点)二分图的必须边:先匈牙利最大匹配,在枚举去掉最大匹配的边,再匈牙利最大匹配,看是否还是等于原来的最大匹配数。。。若不是则为必须边最优匹配 KM算法比较死可见构图的重要性,特别是:对应关系的建立:把看似没联系的问题用二分图建立关系拆点:把一个点分成多个点,使二分图建立 阅读全文

posted @ 2011-07-22 09:26 huhuuu 阅读(206) 评论(0) 推荐(0) 编辑

摘要:左集合毫无疑问n右集合如何构造就可以建立良好的对应关系3 41 100 100 10099 1 99 9998 98 1 98可以拆点建立该图就是把j点拆成3份对应关系就出来了1 2 3 100 200 300 100 200 300 100 200 30099 198 297 1 2 3 99 198 297 99 198 29798 196 294 98 196 294 1 2 3 98 196 294View Code #include<stdio.h>#include<string.h>#define MAXN 2509#define inf 100000000 阅读全文

posted @ 2011-07-22 09:11 huhuuu 阅读(235) 评论(0) 推荐(0) 编辑

摘要:View Code #include<stdio.h>#include<math.h>#include<string.h>#define MAXN 109#define inf 1000000000#define _clr(x) memset(x,0xff,sizeof(int)*MAXN)int mat[109][109];int match1[MAXN];int match2[MAXN];struct data{ int fi,fj; }H[109];struct data1{ int fi,fj;}M[109];int KM(int m,int n,i 阅读全文

posted @ 2011-07-21 15:20 huhuuu 阅读(286) 评论(0) 推荐(0) 编辑

摘要:一开始没看到You should notice that the roads of two different robots may contain some same point. WA了好几次它是说如果1-22-3那么1-3图的传递性可以用floyd快速求解View Code #include<stdio.h>#include<math.h>#include<string.h>int g,m;bool map[509][509];int mark[509];bool flag[509];bool dfs(int x){ int i; for(i=1;i& 阅读全文

posted @ 2011-07-21 10:10 huhuuu 阅读(537) 评论(0) 推荐(0) 编辑

摘要:路径覆盖就是在图中找一些路经,使之覆盖了图中的所有顶点,且任何一个顶点有且只有一条路径与之关联最小路径覆盖就是找出最小的路径条数,使之成为P的一个路径覆盖.最小路径覆盖=顶点数-最大匹配数(貌似与最大独立集同)建图:集合A,B分别放顶点P,P'如果出租车在X点可以Y点,则map[x][y]=1;//因为是X->Y,而题意Y显然无法到X,所以单向图附上测试数据:1500:00 0 0 1 100:02 1 1 2 200:06 2 2 3 300:03 1 1 4 400:12 4 4 5 5输出2View Code #include<stdio.h>#include& 阅读全文

posted @ 2011-07-21 09:21 huhuuu 阅读(1216) 评论(0) 推荐(0) 编辑

摘要:题意是判断二分图的边是否唯一先最大二分匹配下枚举 A集合的点所连接的边 删除在最大二分匹配下看匹配数是否与没删前一样,若不一样,则说明该边是唯一边View Code #include<stdio.h>#include<string.h>bool map[59][59];int mark[59];int rmark[59];bool flag[59];int m,g;struct data{ int minx,miny,maxx,maxy;}node[59];struct data1{ int x,y;}point[59];struct data2{ char str; 阅读全文

posted @ 2011-07-20 19:26 huhuuu 阅读(166) 评论(0) 推荐(0) 编辑

摘要:最大独立集: 在N个点的图G中选出m个点,使这m个点两两之间没有边,求m最大值。如果图G满足二分图条件,则可以用二分图匹配来做。最大独立集点数 = N - 最大匹配数。将孩子看成二分图里的 A,B集若孩子a喜欢的动物号是孩子b喜欢的动物号则连边,因为A,B集是同类,无向图map[a][b]=1;map[b][a]=1;实际上就是最大独立集=顶点数-最大匹配数/2View Code #include<stdio.h>#include<string.h>bool map[509][509];int mark[509];bool flag[509];int m;char A[ 阅读全文

posted @ 2011-07-20 15:45 huhuuu 阅读(848) 评论(2) 推荐(0) 编辑

摘要:裸题。。。View Code #include<stdio.h>#include<string.h>bool map[109][109];int mark[109];bool flag[109];int m;bool dfs(int x){ int i; for(i=1;i<=m;i++) { if(map[x][i]==0||flag[i]) continue; flag[i]=1; if(mark[i]==0||dfs(mark[i])) { mark[i]=x; return 1; } } return 0;}int main(){ int i,g,k,j; 阅读全文

posted @ 2011-07-20 13:52 huhuuu 阅读(148) 评论(0) 推荐(0) 编辑

摘要:主要难点在与拆点举个例子:3. . .X . X. X .在行上拆成1 1 10 2 03 0 4列上拆成1 3 40 3 02 0 5就行了。。。后面一样View Code #include<stdio.h>#include<string.h>bool map[20][20];int hash[5][5];int row[5][5];int lie[5][5];int mark[20];bool flag[20];int m;bool dfs(int x){ int i; for(i=1;i<=m;i++) { if(map[x][i]==0||flag[i]) 阅读全文

posted @ 2011-07-20 11:10 huhuuu 阅读(179) 评论(0) 推荐(0) 编辑

摘要:把行列转化为二分图根据König定理:二分图最小点覆盖数 = 最大匹配数View Code #include<stdio.h>#include<string.h>bool map[505][505];int mark[505];bool flag[505];int m;bool dfs(int x){ int i; for(i=1;i<=m;i++) { if(map[x][i]==0||flag[i]) continue; flag[i]=1; if(mark[i]==0||dfs(mark[i])) { mark[i]=x; return 1; } 阅读全文

posted @ 2011-07-20 08:31 huhuuu 阅读(221) 评论(0) 推荐(0) 编辑

摘要:View Code #include<stdio.h>#include<string.h>bool map[505][505];int men[505];bool hash[505];int m;bool dfs(int x){ int i; for(i=1;i<=m;i++) { if(map[x][i]==0||hash[i]) continue; hash[i]=1; if(men[i]==0||dfs(men[i])) { men[i]=x; return 1; } } return 0;}int main(){ int i,g,k; int count; 阅读全文

posted @ 2011-07-19 15:02 huhuuu 阅读(226) 评论(0) 推荐(0) 编辑

摘要:自己的代码:用到了STL实现:把两个二分集合分别保存在两个set容器里在用queue实现可以对后面有影响的组合先进入set容器View Code #include<stdio.h>#include<set>#include<queue>#include<algorithm>#include<iostream>using namespace std;char hash[209][209];bool x[30009];struct data { int a,b;};int cmp(data x,data y){ return x.a< 阅读全文

posted @ 2011-04-23 10:33 huhuuu 阅读(508) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示