标签:minimum 匈牙利算法 iostream std cross div through present EAP
http://poj.org/problem?id=3041
Description
Input
Output
Sample Input
3 4 1 1 1 3 2 2 3 2
Sample Output
2
Hint
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn = 550;
int N, K;
int mp[maxn][maxn];
int vis[maxn], match[maxn];
int path(int u) {
for(int v = 1; v <= N; v ++) {
if(mp[u][v] && !vis[v]) {
vis[v] = 1;
if(match[v] == -1 || path(match[v])) {
match[v] = u;
return 1;
}
}
}
return 0;
}
int main() {
memset(mp, 0, sizeof(mp));
memset(match, -1, sizeof(match));
scanf("%d%d", &N, &K);
for(int i = 0; i < K; i ++) {
int x, y;
scanf("%d%d", &x, &y);
mp[x][y] = 1;
}
int cnt = 0;
for(int i = 1; i <= N; i ++) {
memset(vis, 0, sizeof(vis));
if(path(i))
cnt ++;
else continue;
}
printf("%d\n", cnt);
return 0;
}
匈牙利算法 求最小点集覆盖
标签:minimum 匈牙利算法 iostream std cross div through present EAP
原文地址:https://www.cnblogs.com/zlrrrr/p/10669651.html