Machine ScheduleTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 6339 Accepted Submission (s): 3178
Problem Descriptionas We all know, machine scheduling are a very classical problem in computer science and have been studied For a very long history. 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, Likew Ise 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.
Inputthe 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.
Outputthe 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
Sourceasia 2002, Beijing (Mainland China)
The main idea: each project can be done by a or b alone, but different tasks need A or b different, the minimum number of restarts to investigate the knowledge point: Hungarian algorithm template
Points of Knowledge: Hungarian algorithm//survey knowledge Point: Hungarian algorithm template title/******************************************************************** int find (int x) {int J; for (J=1;J<M;++J)//Successive traversal of each girl's paper {if (Line[x][j]&&!used[j])//ambiguous with each other and no master { Used[j]=1; if (girl[j]==0| | Find (Girl[j])//Flowers no master or can vacate position {girl[j]=x; Return 1;//find a matching girl paper}}} return 0; } **********************************************************************/#include <stdio.h> #include < String.h>int girl[110],used[110];int line[110][110];int n,m,k;int Find (int x)//Hungarian template {int j;for (J=1;J<=M;++J) { if (!used[j]&&line[x][j]) {used[j]=1;if (!girl[j]| | Find (Girl[j])) {Girl[j]=x;return 1;}}} return 0;} int main () {while (~SCANF ("%d", &n), n) {int a,b,c;memset (used,0,sizeof (used)); memset (line,0,sizeof); memset (Girl,0,sizeof (Girl)); scanf ("%d%d", &m,&k); for (int i=1;i<=K;++i) {scanf ("%d%d%d", &a,&b,&c); line[b][c]=1;} int count=0;for (int i=1;i<=n;++i) {memset (used,0,sizeof (used)), if (Find (i)) {count++;}} printf ("%d\n", count);} return 0;}
Hungarian algorithm template title HDU 1150