hdu 4619 二分图最大匹配 ——最大独立集
2013-07-26 00:23
309 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619
View Code
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn 1001 #define N 105 using namespace std; int map ; bool G[maxn][maxn]; int n,m; int ans; bool vis[maxn]; int link[maxn]; int rnum,lnum; bool match(int u){ for(int v=1;v<rnum;v++){ if(G[u][v] && !vis[v]){ vis[v] = true; if( !link[v] || match(link[v])){ //要么v没有匹配边,要么就递归找; link[v] = u; return true; } } } return false; } void solve(){ memset(link,0,sizeof(link)); ans = 0; for(int i=1;i<lnum;i++){ memset(vis,0,sizeof(vis)); if(match(i)) ans++; } } int main() { //if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} while(cin>>n>>m){ if(n==0 && m==0) break; memset(G,0,sizeof(G)); memset(map,0,sizeof(map)); lnum = 1; for(int i=1;i<=n;i++){ int x,y; scanf("%d%d",&x,&y); map[x][y] = map[x+1][y] = lnum++; // } rnum = 1; for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); if(map[x][y]){ G[map[x][y]][rnum] = true; } if(map[x][y+1]){ G[map[x][y+1]][rnum] = true; } if(map[x][y] || map[x][y+1]) rnum++; } solve(); printf("%d\n",n+m-ans); } }
View Code
相关文章推荐
- hdu 4619 Warm up 2(二分图最大匹配)
- hdu 4619 Warm up 2(最大独立点集,二分匹配,4级)
- hdu 4619 Warm up 2 ( 二分图最大匹配 )
- HDU 4619 —— Warm up 2(二分图最大匹配)
- hdu 2768 Cat vs. Dog(二分图最大匹配--最大独立点集)
- hdu 4619 Warm up 2 ( 二分图最大匹配 )
- hdu_2063,二分图最大匹配的学习
- HDU 1507 Uncle Tom's Inherited Land* 二分图最大匹配(基础题)
- hdu 1054 二分图最大匹配
- hdu-2768-Cat vs. Dog(二分图-最大匹配数)
- hdu 1068 二分图的最大匹配匈牙利算法
- HDU 2255 奔小康赚大钱 (KM算法+二分图最大权匹配)
- hdu 2819 Swap(二分图最大匹配,输出路径)
- hdu 2444 The Accomodation of Students 【二分图判断+求最大匹配】
- HDU 2444 The Accomodation of Students (二分图判定+最大匹配
- hdu 过山车(二分图的最大匹配)
- hdu 3081 二分图最大匹配
- HDU 1565 方格取数(1) 二分图最大点权独立集
- HDU 3729 I'm Telling the Truth(二分图最大匹配)
- HDU 2063 过山车(匈牙利算法)(二分图求最大匹配)