HDU 1150 Machine Schedule minimum point coverage converted to maximum match

Source: Internet
Author: User

Machine Schedule

Time limit:1 Sec Memory limit:256 MB

Topic Connection http://acm.hdu.edu.cn/showproblem.php?pid=1150
Descriptionas we all know, machine scheduling are a very classical problem in computer science and have been studied for a V ery 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. Output

The output should is one integer per line, which means the minimal times of restarting machine.

Sample INPUT5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0Sample Output3HINT

Test instructions

A task can be completed in the state A and B of two machines, two machines have n,m state, the K-task can be done at least in the number of transitions;

Exercises

The n states of a machine and the M states of B as vertices, if task 1 can be completed in the state AI and state bi under the ai--bi of a side to construct a two-part diagram is to find the minimum point coverage problem of the two-part graph is to find the smallest vertex set covering all edges, the two-part map of the number of points = match number Solving

Code:

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<queue>#include<typeinfo>#include<map>#include<stack>typedefLong Longll;#defineINF 0x7fffffffusing namespacestd;inline ll Read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//*************************************************intn,m;intlk[ -];intg[ the][ the];inty[ -];intans;BOOLDfsintv) {     for(intI=1; i<=m;i++){        if(g[v][i]&&!Y[i]) {Y[i]=1; if(lk[i]==0||DFS (Lk[i])) {Lk[i]=v; return 1; }        }    }    return 0;}voidsolve () { for(intI=1; i<=n;i++) {memset (Y,0,sizeof(y)); Ans+=DFS (i); } cout<<ans<<Endl;}intMain () {intK;  while(cin>>N) {if(n==0) Break; CIN>>m>>K; Ans=0; Memset (g,0,sizeof(g)); memset (LK,0,sizeof(LK)); intx,a,b;  for(intI=1; i<=k;i++) {cin>>x>>a>>b;g[a][b]=1;}    Solve (); }    return 0;}

HDU 1150 Machine Schedule minimum point coverage converted to maximum match

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.