POJ 1325 Machine Schedule

Source: Internet
Author: User
Tags define local

Machine Schedule
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 14479 Accepted: 6172

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

Source

Beijing 2002 —————————————————————— I'm gorgeous. Split line ———————————————————————————————— The maximum point coverage of the binary chart.

Minimum point Set overlay-covers all edges with the fewest points.

In this, the side refers to the task, pointing to the machine mode.

The feature in this is that the minimum point set overrides can be used only if the task execution order is not required.

Specifically, the Hungarian algorithm is used to find the maximum number of matching edges-the actual meaning is to find three of the matching edges of the corresponding points, can cover all tasks.

1 /*2 problem:3 OJ:4 User:5 Time :6 Memory:7 Length:8 */9#include <iostream>Ten#include <cstdio> One#include <cstring> A#include <cmath> -#include <algorithm> -#include <queue> the#include <cstdlib> -#include <iomanip> -#include <cassert> -#include <climits> +#include <vector> -#include <list> +#include <map> A #defineMAXN 101 at #defineF (i,j,k) for (int i=j;i<=k;i++) - #defineM (A, B) memset (A,b,sizeof (a)) - #defineFF (i,j,k) for (int i=j;i>=k;i--) - #defineINF 0x7fffffff - #defineMAXM 2016 - #defineMoD 1000000007 in //#define LOCAL - using namespacestd; to intRead () { +     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} the      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} *     returnx*F; $ }Panax Notoginseng intn,m,k; - intMP[MAXN][MAXN]; the intPX[MAXN],PY[MAXN]; + intans; A intCX[MAXN],CY[MAXN]; theInlineintPathintu) + { -cx[u]=1; $F (I,1, M) { $         if(mp[u][i]>0&&!Cy[i]) { -cy[i]=1; -             if(!py[i]| |path (Py[i])) the             { -px[u]=i;Wuyipy[i]=u; the                 return 1; -             } Wu         } -     } About     return 0; $ } -InlinevoidSolve () - { -ans=0; AM (PX,0); M (PY,0); +F (I,1, N) { the         if(!Px[i]) { -M (CX,0); M (CY,0); $ans+=path (i); the         } the     } the     return; the } - intMain () in { theStd::ios::sync_with_stdio (false);//cout<<setiosflags (ios::fixed) <<setprecision (1) <<y; the #ifdef LOCAL AboutFreopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout); the     #endif the      while(cin>>N) +     { -         if(n==0) Break; thecin>>m>>k; M (MP,0);BayiF (I,1, K) { the             inta,b,c; theCin>>a>>b>>C; -mp[b][c]=1; -         } the solve (); thecout<<ans<<Endl; the     } the     return 0; -}
View Code

POJ 1325 Machine Schedule

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.