HDU 1150 Machine Schedule

Source: Internet
Author: User
Machine Schedule
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 103 accepted submission (s): 68
 
Problem descriptionas we all know, machine scheduling is a very classical problem in computer science and has 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 are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1 ,..., Mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1 ,... Mode_m-1. At the beginning they are both work at mode_0.

For K jobs given, each of them can be processed in either one of the two machines in particle mode. for example, job 0 can either be processed in machine a at mode_3 or in machine B at mode_4, Job 1 can either be processed in machine a at mode_2 or in machine B at mode_4, and so on. thus, for job I, the constraint can be represent as a triple (I, x, y), which means it can be processed either in machine a at mode_x, or in machine B at mode_y.

Obviusly, 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 be 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 invocations. the first line of one configuration contains three positive integers: n, m (n, m <100) and K (k <1000 ). the following K lines give the constrains of the K jobs, each line is a triple: I, X, Y.

The input will be terminated by a line containing a single zero.
Outputthe output shocould be 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)
Recommendignatius. L

 

 

The question is given with K tasks and then there are two types of machines A and B (machine A has n medium mode and machine B has M mode ), task ki can be completed in ax or by mode,

Then the machine needs to be restarted during the mode conversion, and then requires the minimum number of restarts to complete all the tasks.

It took a long time to solve the problem of least point coverage with the maximum binary matching, that is, to overwrite all the edges (associated with edges) with a small amount of vertices.

Then, we need to regard the task as a side-by-side graph and find the maximum matching.

 

 

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 111;int n , m , k;int g[N][N] , lx[N];bool vis[N];bool dfs(int u ){    for(int v = 1; v < m ; ++v ){        if( g[u][v] && !vis[v] ){            vis[v] = 1 ;            if( lx[v] == -1 ||dfs (lx[v]) ){                lx[v] = u ;                return true ;            }        }    }    return false ;}int KM(){    int res = 0;    memset(lx , -1 ,sizeof lx );    for(int i = 1 ; i < n ; ++i ){        memset (vis , false , sizeof vis );        if( dfs(i) ) res++;    }    return res ;}int main(){    #ifdef LOCAL        freopen("in.txt","r",stdin);    #endif    int a , x , y ;    while(cin>>n){        if(!n)break;        cin>>m>>k;        memset(g , 0 ,sizeof  g) ;        while(k-- )        {            cin>>a >> x >> y ;            if(x == 0 || y == 0 ) continue;            g[x][y] = 1 ;        }        printf("%d\n",KM());    }    return 0 ;}

 

HDU 1150 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.