二部圖匹配算法(求最大匹配數(shù))_第1頁
二部圖匹配算法(求最大匹配數(shù))_第2頁
二部圖匹配算法(求最大匹配數(shù))_第3頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、二部圖匹配算法(求最大匹配數(shù))Machine ScheduleProblem 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 desire

2、d. 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

3、 given, each of them can be processed in either one of the two machines in particular 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 con

4、straint 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.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 on

5、ly 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 configurations. The first line of one configuratio

6、n 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 should be one integer per line, which means the minim

7、al times of restarting machine.Sample Input5 5 100 1 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30Sample Output3#include <stdio.h>#define N 100#define M 100int useifM; /記錄當(dāng)前y中節(jié)點是否使用int linkM; /記錄當(dāng)前與y節(jié)點相連的x的節(jié)點int mapNM;/記錄連接x和y的邊,如果i和j之間有邊則為1,否則為0int n, m; /二分圖中x和y中點的數(shù)目int k; /預(yù)設(shè)的邊數(shù) int match

8、(int x) /從X向Y中找匹配點,形成匹配邊X<->Y int i; for(i=1;i<=m;i+) if(useifi=0 && mapxi) useifi=1; if(linki=-1 | match(linki) linki=x; /printf("map a%d to b%dn", x, i); return 1; return 0;int MaxMatch()/為每一個X點找Y匹配點,形成最大匹配 int i, num=0; memset(link,-1,sizeof(link); for (i=1; i<=n; i+) memset(useif,0,sizeof(useif); if(match(i) num+; return num;int Init() int i, s, x, y; scanf("%d", &n); if (n=0) return 0; scanf("%d%d",&m,&k); memset(map,0,sizeof(map); for (i=1; i<=k; i+) scanf("%d%d%d",

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論