二分图最小顶点覆盖 hdu1150
来源:互联网 发布:最好网络合理理财 编辑:程序博客网 时间:2024/06/04 20:11
http://acm.hdu.edu.cn/showproblem.php?pid=1150
在二分图中求最少的点,让每条边都至少和其中的一个点关联,这就是“二分图的最小顶点覆盖”。
最小顶点覆盖=最大匹配数
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;const int MAXN=105;int m1,m2;int g[MAXN][MAXN];int used[MAXN];int linker[MAXN];int dfs(int u){ for(int v=1;v<m2;v++) { if(g[u][v]&&!used[v]) {used[v]=1; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } } return false;}int hungary(int m1){ int res=0; memset(linker,-1,sizeof(linker)); for(int u=1;u<m1;u++) { memset(used,0,sizeof(used)); if(dfs(u))res++; } return res;}int main(){int num; while(cin>>m1) {memset(g,0,sizeof(g)); if(m1==0)break; cin>>m2>>num; for(int i=0;i<num;i++) {int v1,v2,n; cin>>n>>v1>>v2; g[v1][v2]=1; } cout<<hungary(m1)<<endl; } return 0;}
0 0
- 二分图最小顶点覆盖 hdu1150
- hdu1150(二分图最小顶点覆盖)
- HDU1150-- Machine Schedule( 二分图最小顶点覆盖)
- hdu1150 Machine Schedule (二分图的最小顶点覆盖)
- HDU1150最小顶点覆盖
- HDU1150 Machine Schedule(最小顶点覆盖)
- hdu1150 二分图匹配的最小点覆盖
- 【HDU1150】【建模】【最小点覆盖】【二分匹配】
- poj3041_Asteroids_二分图最小顶点覆盖
- hdu 1150二分图最小顶点覆盖
- poj1325_二分图最小顶点覆盖集
- hud1150二分图最小顶点覆盖
- poj3041 二分图最小顶点覆盖
- hdu 1498(二分图最小顶点覆盖)
- Asteroids POJ3041 二分图最小顶点覆盖
- poj-3041【二分图最小顶点覆盖】
- hdu1498二分图最小顶点覆盖
- hdu1150 最小点覆盖
- boost的signal和solt机制
- 树形dp 入门
- 浅析linux下core文件及调试
- CAMetalLayer 浅析
- 线程的乱序执行,可能会得到意想不到的结果
- 二分图最小顶点覆盖 hdu1150
- sql语句大全
- scala学习之路:10. Abstract抽象类抽象字段抽象方法
- linux下安装boost
- 单例模式分析
- java面试题5
- 利用SecureCRT上传、下载文件
- 矩形面积交
- 如何在win7下远程控制ubuntu