Topic Links:
http://poj.org/problem?id=1325
Main topic:
There are two machines A and B, machine A has N different modes, numbered 0~n-1. Machine B has different modes of M, numbered 0~m-1.
At the very beginning, both machines A and B are in 0 mode. Two machines are now required to handle the K-task, with the task number 0~k-1. Every
A task can be completed in the specified state of a or B. For example, Task 1 can be done in machine A's 2 mode, or in Machine B's 4
the mode is complete. For the I want task (I,x,y) to indicate that the I task can be done in machine A's X mode or machine B's Y mode.
In order to complete all tasks, the machine's working mode must not be switched over and over again. The operating mode of the switch machine can only be completed by restarting the machine.
Yes. So the question is: at least how many times to restart the machine, to complete the K task.
Ideas:
Create a two-part diagram with machine A on one side and Machine B on the other. A task can be done either in the X mode of machine A or in the Y mode of machine B
, an edge (x, y) is created in the binary graph. The minimum number of machine switches is to find out if there is a minimum-scale set of points, so
All edges are associated with at least one point in the point set, that is, the minimum point set overlay of the binary graph. And the minimum point coverage of the two-fractal graph
The maximum matching of the binary graph can be obtained directly with the Hungarian algorithm.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;const int maxn = 110;bool map[maxn][maxn],mask[maxn];int nx,ny;int cx[maxn],cy[maxn];int FindPath (int u) {for (int i = 0; i < NY; ++i) {if (Map[u][i] &&! Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | | Findpath (Cy[i])) {Cy[i] = u; Cx[u] = i; return 1; }}} return 0;} int Maxmatch () {for (int i = 0; i < NX; ++i) cx[i] = 1; for (int i = 0; i < NY; ++i) cy[i] = 1; int res = 0; for (int i = 0, i < NX; ++i) {if (cx[i] = = 1) {for (int j = 0; j < NY; ++j) MASK[J] = 0; Res + = Findpath (i); }} return res;} int main () {int n,m,k,a,u,v; while (~SCANF ("%d", &n) && N) {memset (map,0,sizeof (MAP)); scanf ("%d%d", &m,&k); NX = N,ny = M; for (int i = 1; I <= K; ++i) {scanf ("%d%d%d", &a,&u,&v); if (u*v! = 0) Map[u][v] = 1; } printf ("%d\n", Maxmatch ()); } return 0;}
POJ1325 machine Schedule "The minimum point overlay of the binary graph"