标签:fine include 必须 问题 对组 efi logs contain 想法
6 3 3 1 1 1 2 1 3 2 1 2 3 3 1 0Sample Output
3
匈牙利算法,二分图最大匹配
代码:
#include <stdio.h> #include <string.h> #define inf 0x3ffffff int mp[501][501],dis[501],vis[501]; int n,m,k; int find_b(int d)//寻找匹配 { for(int i = 1;i <= m;i ++) { if(!vis[i] && mp[d][i]) { vis[i] = 1; if(!dis[i] || find_b(dis[i])) { dis[i] = d; return 1; } } } return 0; } int main() { while(~scanf("%d",&k)&&k) { int c = 0,a,b; scanf("%d%d",&n,&m); memset(mp,0,sizeof(mp)); memset(dis,0,sizeof(dis)); for(int i = 0;i < k;i ++) { scanf("%d%d",&a,&b); mp[a][b] = 1; } for(int i = 1;i <= n;i ++) { memset(vis,0,sizeof(vis));//每次寻找匹配前都更新,仅仅是防止每次查找时重复访问 if(find_b(i))c ++; } printf("%d\n",c); } }
标签:fine include 必须 问题 对组 efi logs contain 想法
原文地址:http://www.cnblogs.com/8023spz/p/7800420.html