HDU 1068 ( Bipartite Matching )
来源:互联网 发布:淘宝苹果数据线 编辑:程序博客网 时间:2024/06/05 15:44
二分匹配
我的理解是二分匹配是建立在二分图上边寻找一个两个集合一对一的匹配。
就像是婚配。
这道题是数字之间的喜欢。不分男女,按原来匈牙利的做法,求出来是男数字与女数字之间的匹配,所以只要将匹配的结果除以2,就是所谓的“一分图”匹配数量,就可以用刚刚的公式:二分图的最大独立集=节点数-最大匹配数(这里求的是孤单数字的数目)。
#include<cstdio>#include<cstring>#include<iostream>#include<queue>using namespace std;const int N=505;int line[N][N];int girl[N],used[N];int m,n;bool found(int x){ for(int i=0; i<n; i++) { if(line[x][i]&&!used[i]) { used[i]=1; if(girl[i]==0||found(girl[i])) { girl[i]=x; return 1; } } } return 0;}int main(){ //freopen("in.txt","r",stdin); int x,y; while(scanf("%d",&n) != EOF && n) { memset(line,0,sizeof(line)); memset(girl,0,sizeof(girl)); for(int j = 1;j <= n; j++) { scanf("%d: (%d)",&x,&m); for(int i=0; i<m; i++) { scanf("%d",&y); line[x][y]=1; } } int sum=0; for(int i=0; i<n; i++) { memset(used,0,sizeof(used)); if(found(i)) sum++; } printf("%d\n",n-sum/2); } return 0;}
0 0
- HDU 1068 ( Bipartite Matching )
- Bipartite Matching
- 【资料】Maximum Bipartite Matching
- Maximum Bipartite Matching
- hdu 5313 Bipartite Graph
- hdu-5313 Bipartite Graph
- hdu 5313 Bipartite Graph
- HDU 5313 Bipartite Graph
- [HDU 5354] Bipartite Graph
- Max bipartite matching with Ford-Fulkerson algorithm
- 【染色】 HDU 5313 Bipartite Graph
- hdu 5313 Bipartite Graph 贪心+bfs染色
- 【HDU】5313 Bipartite Graph【二分图+背包】
- HDU 5313 Bipartite Graph(bitset + DP)
- HDU 1045 Fire Net 二分图Bipartite题解
- [HDU 5313] Bipartite Graph 二分图染色+分组背包
- HDU 5313 BestCoder 1st Anniversary ($) 1004 Bipartite Graph
- hdu 5313 Bipartite Graph 完全二分图 深搜 bitset应用
- uva 725 Division 暴力求解入门
- Python相关常用库概念介绍
- IntelliJ IDEA 工具技巧
- Web Api 分类
- 2016.3pycharm破解码
- HDU 1068 ( Bipartite Matching )
- 求海量文本中两两相似文本的快速算法
- SNAP-The SENTINEL-1 Toolbox
- Let the Balloon Rise
- 70. Climbing Stairs
- idTCPSever得到连接IP和端口。
- iOS开发之App主题切换完整解决方案(Swift版)
- 带权的完备二分匹配问题
- Linux下文件操作