Test instructions: There are n-piece t-shirts, N is a multiple of 6, because there are 6 models, each of the same number of pieces, there are m individuals, each person has two models of T-shirt suitable for him, everyone can pick one of them, ask whether all the people can be assigned to T-shirts.
Analysis: The typical two-figure matching, each N/6 for the same kind of T-shirts, for a single person, he and it is suitable for the two T-shirts with all the markings of the edge, the final calculation of the maximum match, if less than M, it is not feasible, otherwise feasible.
The code is as follows:
#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<set>#include<map>#include<queue>#include<vector>#include<iterator>#include<utility>#include<sstream>#include<iostream>#include<cmath>#include<stack>UsingNamespace Std;Constint INF=1000000007;ConstDouble EPS=0.00000001;Vector<int>G[40];int Le[40],ri[40];int NM;StringType[]={S,M,L,"XS","XL","XXL"}; 6 Different models of T-shirtsBOOL Vis[40];boolDfs(int cur)//two graph matching template{If(Vis[cur])ReturnFalse; Vis[cur]=True;For(int I=0; I<g[cur].Size(); I++){int to=g[cur][i];If*r+[To]==-1||Dfs*r+[To])){Le[cur]=to; Ri[To]=cur;ReturnTrue;}}ReturnFalse;}boolMatch(){int ret=0;Memset(Le,-1,sizeof(Le));Memset*r+,-1,sizeof*r+));For(int I=1; I<=n; I++){Memset(Vis,False,sizeof(Vis));If(Dfs(I)) RET++; If you can match, add 1If(ret==m)ReturnTrue; Reach M, direct return to True}ReturnFalse;}IntMain(){int T; Cin>>t;Map<string,int>Ma;For(int I=0; I<6; I+ +) Ma[Type[I]]=i; Map T-shirt models to numbersWhile(T--){cin>>n>>m;For(int I=1; I<=n; I+ +) G[I].Clear();int every=n/6;StringAB;For(int I=1; I<=m; I++){cin>>a>>b;int a=ma[A],b=ma[B];For(Int St=a*every+1=s2<= (A+1) *every=s2+ +) G[St].Push_back(I); Establish a pro-link table, with the label of all T-shirts as a sideFor(Int St=b*every+1=s2<= (b+1) *every=s2+ +) G[st]. Push_back if (Match () printf (\n "); else printf ( "No\n" ); return 0;< Span class= "Sh-cbracket" >
UVA 11045-my T-shirt suits me (binary image matching)