标签:style blog color strong for 问题 ar div
The Hungarian algorithm with The adjacency matrix :
计算最大匹配问题
int n1, n2, m, ans; int res[MAXN]; bool vis[MAXN], map[MAXN][MAXN]; void init(){ int t1, t2; memset(map, 0, sizeof(map)); memset(res, 0, sizeof(res)); ans = 0; scanf("%d%d",&n1,&n2); //get map[][] } bool find(int a) { for (int i = 1; i <= n2; ++i) { if (map[a][i] == 1 && !vis[i]) { vis[i] = true; if (res[i] == 0 || find(res[i])) { res[i] = a; return true; } } } return false; } int main() { init(); for (int i = 1; i <= n1; ++i) { memset(vis, 0, sizeof(vis)); if (find(i)) ++ans; } printf("%d\n",ans); return 0; }
The Hungarian algorithm Template,布布扣,bubuko.com
The Hungarian algorithm Template
标签:style blog color strong for 问题 ar div
原文地址:http://www.cnblogs.com/wushuaiyi/p/3894133.html