POJ-1274-The Perfect Stall 解题报告
2014-11-12 15:47
417 查看
求二分图最大匹配。题意:农夫的牛栏上个星期刚刚完成。但是因为工程设计问题,所有的牛栏都不一样。第一个星期,农夫为他的牛随意分配了牛栏。但是他很快地意识到有一些牛只在指定的牛栏中才会产奶。他想尽可能多的使牛能够产奶,但是每一头牛只能分配给一个牛栏且每一个牛栏也只能被一头牛分配到。请你计算出最多能分配多少对使得牛产奶最多。
我的解题思路:这是赤裸裸的求二分图最大匹配,不用多说。
我的解题代码:
我的解题思路:这是赤裸裸的求二分图最大匹配,不用多说。
我的解题代码:
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> using namespace std; #define N 202 int match ; bool vis ; vector <int> e ; int n, m; void InitRead(); void DataProcess(); bool Dfs(int x); int main() { while (~scanf("%d %d", &n, &m)) { InitRead(); DataProcess(); } return 0; } void InitRead() { memset(match, -1, sizeof(match)); int a, b; for (int i=1; i<=n; ++i) { e[i].clear(); scanf("%d", &a); while (a--) { scanf("%d", &b); e[i].push_back(b); } } return; } void DataProcess() { int ans = 0; for (int i=1; i<=n; ++i) { memset(vis, false, sizeof(vis)); if (Dfs(i)) ans++; } printf("%d\n", ans); return; } bool Dfs(int x) { int size = e[x].size(); for (int i=0; i<size; ++i) { if (!vis[e[x][i]]) { vis[e[x][i]] = true; if (match[e[x][i]] == -1 || Dfs(match[e[x][i]])) { match[e[x][i]] = x; return true; } } } return false; }
相关文章推荐
- POJ 1274 The Perfect Stall 解题报告
- Pku acm 1274 The Perfect Stall 数据结构题目解题报告(十三)---- 匈牙利算法求二分图的最大匹配
- POJ 1274 The Perfect Stall ( 匈牙利算法 )
- poj 1274 The Perfect Stall
- poj1274 - The Perfect Stall
- 【最大流】北大 poj 1274 The Perfect Stall
- POJ 1274 The Perfect Stall(二分图最大匹配)
- poj 1274 The Perfect Stall
- poj 1274 The Perfect Stall(匈牙利算法)
- 【二分图+最大匹配】北大 poj 1274 The Perfect Stall
- POJ-1274 The Perfect Stall 二分匹配
- poj 1274 The Perfect Stall
- 二分图最大基数匹配 POJ 1274 The Perfect Stall
- POJ1274 The Perfect Stall [二分图最大匹配 匈牙利算法]
- POJ 1274 The Perfect Stall 二分图最大匹配
- POJ 1274 The Perfect Stall (第一道二分图最大配对)
- poj 1274 The Perfect Stall (Hungary Very good! 入门)
- poj The Perfect Stall 1274 最大二分匹配
- POJ 1274 The Perfect Stall
- POJ 1274 The Perfect Stall (匈牙利算法)