标签:ace false print std namespace || list ack tin
[题目链接]
http://poj.org/problem?id=2239
[算法]
将课程作为左部节点,时间作为右部节点,用匈牙利算法求二分图最大匹配即可
[代码]
#include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <exception> #include <fstream> #include <functional> #include <limits> #include <list> #include <map> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <vector> #include <cwchar> #include <cwctype> #include <stack> #include <limits.h> using namespace std; #define MAXN 350 const int T = 84; struct edge { int to,nxt; } e[MAXN * T]; int i,n,m,x,y,ans,tot; bool visited[MAXN + T]; int match[MAXN + T],head[MAXN + T]; inline void addedge(int u,int v) { tot++; e[tot] = (edge){v,head[u]}; head[u] = tot; } inline bool hungary(int u) { int i,v; visited[u] = true; for (i = head[u]; i; i = e[i].nxt) { v = e[i].to; if (!visited[v]) { visited[v] = true; if (!match[v] || hungary(match[v])) { match[v] = u; return true; } } } return false; } int main() { while (scanf("%d",&n) != EOF) { tot = 0; memset(match,0,sizeof(match)); for (i = T + 1; i <= T + n + 1; i++) head[i] = 0; for (i = 1; i <= n; i++) { scanf("%d",&m); while (m--) { scanf("%d%d",&x,&y); addedge(i + T,12 * (x - 1) + y); } } ans = 0; for (i = T + 1; i <= T + n + 1; i++) { memset(visited,false,sizeof(visited)); if (hungary(i)) ans++; } printf("%d\n",ans); } return 0; }
标签:ace false print std namespace || list ack tin
原文地址:https://www.cnblogs.com/evenbao/p/9406485.html