The different modes of the machine for the point, for each job, build two side a machine required mode <->B machine required mode.
The problem is converted to the minimum point overlay, and then the minimum point of the binary graph is used to overwrite = = maximum match, using the Hungarian algorithm.
#include <cstdio> #include <cstring>const int n=105<<1;const int m=1001<<1;struct edge{int to, Next;} E[m];int head[n],tot;void Add (int u,int v) {e[tot].to=v;e[tot].next=head[u];head[u]=tot++;} void Init () {Tot=0;memset (head,-1,sizeof head);} int n,vis[n],link[n];int find (int u) {for (int i=head[u];~i;i=e[i].next) {int v=e[i].to;if (!vis[v]) {vis[v]=1;if (!link[ v]| | Find (Link[v])) {Link[v]=u;return 1;}}} return 0;} int solve () {memset (link,0,sizeof link), int ans=0;for (int i=1;i<=n;i++) {memset (vis,0,sizeof Vis), if (Find (i)) ans++ ;} return ans;} int main () {int k,m,u,v;while (scanf ("%d", &n), n) {init (); scanf ("%d%d", &m,&k), while (k--) {scanf ("%d%d%d", &M,&U,&V); add (u,v+n); add (v+n,u);} printf ("%d\n", Solve ());}}
"HDU 1150" machine Schedule (binary graph matching)