Machine Schedule
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 14375 |
|
Accepted: 6135 |
Description
As we all know, machine scheduling are a very classical problem in computer science and have been studied for a very long hi Story. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired . Here we consider a 2-machine scheduling problem.
There was machines a and B. Machine A have n kinds of working modes, which is called Mode_0, Mode_1, ..., mode_n-1, lik Ewise machine B has m kinds of working modes, MODE_0, Mode_1, ..., mode_m-1. At the beginning they is both work at Mode_0.
For k jobs given, each of the them can is processed in either one of the one of the both machines in particular mode. For example, job 0 can either is processed in machine A at mode_3 or in machine B at Mode_4, Job 1 can either be processed In machine A is mode_2 or in machine B at Mode_4, and so on. Thus, for Job I, the constraint can is represent as a triple (I, X, y), which means it can be processed either A at mode_x, or in machine B at mode_y.
Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, The machine's working mode can only is changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the Times of restarting machines.
Input
The input file for this program consists of several configurations. The first line of one configuration contains three positive integers:n, M (N, M <) and K (K < 1000). The following k lines give the constrains of the K jobs, each of which is a triple:i, X, Y.
The input would be terminated to a line containing a single zero.
Output
The output should is one integer per line, which means the minimal times of restarting machine.
Sample Input
5 5 100 1 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30
Sample Output
3
"Analysis" requires the minimum point cover set problem of the two-part graph, that is, to find the smallest vertex set, covering the point of the residence. The maximum matching problem for the two-part graph is converted, because: the number of point overlays = = matches of two graphs.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<functional>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll;Const intn= the;Const intm=15005;intNx,ny;intjob;intEdg[n][n];intans=0;intVisx[n],visy[n];intCx[n],cy[n];intDfsintu) {Visx[u]=1; for(intv=1; v<=ny;v++){ if(edg[u][v]&&!Visy[v]) {Visy[v]=1; if(!cy[v]| |DFS (Cy[v])) {Cx[u]=v;cy[v]=T; return 1; } } } return 0;}intsolve () {memset (CX),0,sizeof(CX)); memset (CY,0,sizeof(CY)); for(intI=1; i<=nx;i++){ if(!Cx[i]) {memset (VISX,0,sizeof(VISX)); memset (Visy,0,sizeof(Visy)); Ans+=DFS (i); } }}intMain () {intx,y,m; scanf ("%d%d%d",&nx,&ny,&job); memset (EDG,0,sizeof(EDG)); for(intI=0; i<job;i++) {scanf ("%d%d%d",&m,&x,&y); Edg[x][y]=1; } solve (); printf ("%d\n", ans); return 0;}
View Code
Poj1325machine Schedule (Hungarian algorithm)