标签:display str 匹配 show for mes syn name out
链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=2006
思路:
二分匹配 注意n m的关系
代码:
1 #include <iostream> 2 #include <string.h> 3 using namespace std; 4 int g[105][105],vis[105],who[105]; 5 int n,m; 6 bool find(int x) { 7 for(int i=m+1; i<=n; ++i) { 8 if(g[x][i]&&!vis[i]) { 9 vis[i]=1; 10 if(!who[i]||find(who[i])) { 11 who[i]=x; 12 return true; 13 } 14 } 15 } 16 return false; 17 } 18 int main() { 19 ios::sync_with_stdio(false); 20 memset(g,0,sizeof(g)); 21 memset(who,0,sizeof(who)); 22 int u,v,sum; 23 cin>>m>>n; 24 while(cin>>u>>v) { 25 if(u==-1&&v==-1) break; 26 g[u][v]=1; 27 } 28 sum=0; 29 for(int i=1; i<=m; ++i) { 30 memset(vis,0,sizeof(vis)); 31 if(find(i)) sum++; 32 } 33 cout<<sum<<endl; 34 return 0; 35 }
标签:display str 匹配 show for mes syn name out
原文地址:http://www.cnblogs.com/lemonbiscuit/p/7845840.html