机器A的所有模式为左部顶点,机器B的所有模式为右部顶点,然后A与B之间的每条连线代表一个任务或工作
之后就要完成所有的任务,即将每条边都覆盖
对一个有向图,若要覆盖每条边,至少需要的点数为二分图最大匹配数
建图的方法还是拆点。
代码如下
/*
ID: sdj22251
PROG: inflate
LANG: C++
*/
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#define MAXN 105
#define INF 1000000000
using namespace std;
int nx, ny;
vector<int>g[MAXN];
int cx[MAXN], cy[MAXN];
int mark[MAXN];
int path(int u)
{
int x = g[u].size();
for(int i = 0; i < x; i++)
{
int v = g[u][i];
if(!mark[v])
{
mark[v] = 1;
if(cy[v] == -1 || path(cy[v]))
{
cx[u] = v;
cy[v] = u;
return 1;
}
}
}
return 0;
}
int maxmatch()
{
int res = 0;
memset(cx, -1, sizeof(cx));
memset(cy, -1, sizeof(cy));
for(int i = 1; i <= nx; i++)
{
if(cx[i] == -1)
{
memset(mark, 0, sizeof(mark));
res += path(i);
}
}
return res;
}
int main()
{
while(scanf("%d", &nx) != EOF && nx)
{
int t, x, y;
nx--;
for(int i = 0; i <= nx; i++)
g[i].clear();
scanf("%d%d", &ny, &t);
ny--;
while(t--)
{
scanf("%*d%d%d", &x, &y);
if(!x || !y) continue;
g[x].push_back(y);
}
printf("%d\n", maxmatch());
}
return 0;
}
分享到:
相关推荐
北大POJ1276-Cash Machine 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
北大POJ1276试题代码
POJ 最接近点对问题 ACM北大 using namespace std; struct Point { float x; float y; };
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
poj 2206 Magic Multiplying Machine.md
POJ2009年最新版,相当详细.................
北大POJ2002-Squares 解题报告+AC代码
poj分类poj分类poj分类poj分类
poj 2827 Auto-Calculation Machine.md
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
北大POJ1159-Palindrome 解题报告+AC代码
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
poj 百练 题目分类 poj 百练 题目分类
POJ1083的代码,POJ1083的代码,POJ1083的代码
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友