匈牙利算法
模板题:hdu1083 Courses
int n,match[510],book[510];
vector<int> g[510];
bool dfs(int u){
book[u]=1;
for(int v:g[u]){
int w=match[v];
if(w<0 || (!book[w] && dfs(w))){
match[u]=v;
match[v]=u;
return true;
}
}
return false;
}
int matching(){
int ans=0;
memset(match,-1,sizeof(match));
for(int i=1;i<=n;i++){
if(match[i]<0){
memset(book,0,sizeof(book));
if(dfs(i)) ans++;
}
}
return ans;
}