This question is the reference network each big gather the code to write out, no way I am too weak
Test instructions
Give you yin and yang beads each n, let you string into yin and yang and the string.
I'll give you a pair of M to show that a certain Yang bead will darken when it is adjacent to a yin bead.
Ask you at least how many yang beads are dimmed
Ideas:
I thought it might have something to do with the dichotomy, but there was no good idea.
I saw the puzzle on the Internet.
It is probably the first enumeration of all the n-1 of the yin Beads (ring arrangement)! Two
Then for each kind of arrangement to not darken the Yang beads and the yin beads to build the side run Hungary
Get the maximum match again with N-it
Ans Take the smallest one, yes.
/************************************************author:d evilcreated time:2016/7/20 17:8:19****************** ****************************** */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespaceStd;typedefLong LongLL;Const intinf=0x3f3f3f3f;Const intn=Ten;intN,m,u,v,ans,pos[n],link[n];BOOLS[n][n],vis[n];vector<int>Eg[n];BOOLDfsintu) { for(intI=0; I<eg[u].size (); i++) { intv=Eg[u][i]; if(!Vis[v]) {Vis[v]=1; if(link[v]==-1||DFS (Link[v])) {Link[v]=T; return 1; } } } return 0;}voidsolve () {memset (s),0,sizeof(s)); while(m--) {scanf ("%d%d",&u,&v); S[U][V]=1; } ans=inf; for(intI=1; i<=n; i++) Pos[i]=i; Do{memset (link),-1,sizeof(link)); for(intI=1; i<=n; i++) {eg[i].clear (); for(intj=1; j<=n; J + +) {u=Pos[i]; if(i==1) v=Pos[n]; Elsev=pos[i-1]; if(s[j][u]| | S[J][V])Continue; Eg[i].push_back (j); } } intnow=0; for(intI=1; i<=n; i++) {memset (Vis,0,sizeof(VIS)); now+=DFS (i); } ans=min (ans,n-Now ); } while(Next_permutation (pos+2, pos+n+1) &&ans); printf ("%d\n", ans);}intMain () {//freopen ("In.txt", "R", stdin); while(~SCANF ("%d%d",&n,&m)) {if(!N) {puts ("0"); Continue; } solve (); } return 0;}
HDU5727 Necklace (Ring row + Hungary)