标签:des style blog http java color
Description
Input
Output
Sample Input
5 5 2 2 5 3 2 3 4 2 1 5 3 1 2 5 1 2
Sample Output
4
这就是一道二分图最大匹配的题目,以前做过了,这次本来是要刷网络流的,不知道为什么挂了几道二分图的题目,还是做了吧
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int map[201][201]; int link[201],use[201],n,m; bool dfs(int cap) { for (int i=1;i<=m;i++) { if(map[cap][i] && !use[i]) { use[i]=1; int j=link[i]; link[i]=cap; if(j==-1 || dfs(j)) return true; //else return false; link[i]=j; } } return false; } int hugry() { int ans=0; memset(link,-1,sizeof(link)); for (int i=1;i<=n;i++) { memset(use,0,sizeof(use)); if(dfs(i)) ans++; } return ans; } int main() { //freopen("in.txt","r",stdin); int x,num; while(scanf("%d%d",&n,&m)!=EOF) { memset(map,0,sizeof(map)); for (int i=1;i<=n;i++) { scanf("%d",&num); for (int j=1;j<=num;j++) { scanf("%d",&x); map[i][x]=1; } } printf("%d\n",hugry()); } //fclose(stdin); return 0; }
poj 1274 The Perfect Stall,码迷,mamicode.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/chensunrise/p/3699581.html