标签:
Description
Input
Output
Sample Input
5 5 10 0 1 1 1 1 2 2 1 3 3 1 4 4 2 1 5 2 2 6 2 3 7 2 4 8 3 3 9 4 3 0
Sample Output
3
求最小覆盖
1 #include <iostream> 2 #include <sstream> 3 #include <fstream> 4 #include <string> 5 #include <vector> 6 #include <deque> 7 #include <queue> 8 #include <stack> 9 #include <set> 10 #include <map> 11 #include <algorithm> 12 #include <functional> 13 #include <utility> 14 #include <bitset> 15 #include <cmath> 16 #include <cstdlib> 17 #include <ctime> 18 #include <cstdio> 19 #include <cstring> 20 #define FOR(i, a, b) for(int i = (a); i <= (b); i++) 21 #define RE(i, n) FOR(i, 1, n) 22 #define FORP(i, a, b) for(int i = (a); i >= (b); i--) 23 #define REP(i, n) for(int i = 0; i <(n); ++i) 24 #define SZ(x) ((int)(x).size ) 25 #define ALL(x) (x).begin(), (x.end()) 26 #define MSET(a, x) memset(a, x, sizeof(a)) 27 using namespace std; 28 29 30 typedef long long int ll; 31 typedef pair<int, int> P; 32 int read() { 33 int x=0,f=1; 34 char ch=getchar(); 35 while(ch<‘0‘||ch>‘9‘) { 36 if(ch==‘-‘)f=-1; 37 ch=getchar(); 38 } 39 while(ch>=‘0‘&&ch<=‘9‘) { 40 x=x*10+ch-‘0‘; 41 ch=getchar(); 42 } 43 return x*f; 44 } 45 const double pi=3.14159265358979323846264338327950288L; 46 const double eps=1e-6; 47 const int mod = 1e9 + 7; 48 const int INF = 0x3f3f3f3f; 49 const int MAXN = 1005; 50 const int xi[] = {0, 0, 1, -1}; 51 const int yi[] = {1, -1, 0, 0}; 52 53 54 int used[MAXN], line[MAXN][MAXN], girl[MAXN]; 55 int N, T; 56 int n, m; 57 bool dfs(int i){ 58 for(int j = 1; j <= m; j++){ 59 if(line[i][j] && !used[j]){ 60 used[j] = 1; 61 if(girl[j] == 0 || dfs(girl[j])){ 62 girl[j] = i; 63 return true; 64 } 65 } 66 } 67 return false; 68 } 69 int main() { 70 //freopen("in.txt", "r", stdin); 71 while(~scanf("%d", &n) && n) { 72 scanf("%d%d", &m, &T); 73 memset(line, 0, sizeof(line)); 74 while(T--) { 75 int x, y; 76 scanf("%d%d%d", &N, &x, &y); 77 line[x][y] = 1; 78 } 79 int all = 0; 80 memset(girl, 0, sizeof(girl)); 81 for(int i = 1; i <= n; i++) { 82 memset(used, 0, sizeof(used)); 83 if(dfs(i)) all++; 84 } 85 printf("%d\n", all); 86 } 87 88 return 0; 89 }
Poj1325 Machine Schedule 最大二分图匹配 匈牙利算法
标签:
原文地址:http://www.cnblogs.com/cshg/p/5783385.html