Give you yin and yang ball each n, some Yang ball as long as there is a ball around, will darken, ask at least how many to darken.
See the puzzle, said is the full array of Yin ball, because into the ring, so can become 8! Complexity, you can run.
Then in each case, if a yang ball hit the surrounding two balls are not dimmed, so long can be placed in this position, at this time the maximum match is this scheme, the maximum can be put, and not darkened, the number. Take n a minus, and take the minimum value on the line. is violence.
And then there's a better function next ... (Bulabula), directly get the whole arrangement.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<string>#include<cstdlib>#include<vector>#include<Set>#include<map>using namespaceStd;vector<int>e[Ten];intmp[Ten][Ten];intlinker[Ten];intvis[Ten];intpos[Ten];intDfsintu) { for(intI=0; I<e[u].size (); i++) { intv=E[u][i]; if(!Vis[v]) {Vis[v]=1; if(linker[v]==-1||DFS (Linker[v])) {Linker[v]=T; return 1; } } } return 0;}intMain () {intN,m,ans; while(SCANF ("%d%d", &n,&m)! =EOF) {memset (MP,0,sizeof(MP)); while(m--) { intt1,t2; scanf ("%d%d",&t1,&T2); MP[T1][T2]=1; } if(n==0) {printf ("0\n"); } Else{ans=Ten; for(intI=1; i<=n; i++) Pos[i]=i; Do { for(intI=1; i<=n; i++) e[i].clear (); for(intI=1; i<=n; i++)//plus side, I is the yin Groove, Yang { intu=Pos[i]; intv; if(i==n) v=pos[1]; Elsev=pos[i+1]; for(intj=1; j<=n;j++)//for each Yang ball, the Yin { if(mp[j][u]| | MP[J][V])Continue;//Yang Yin does not conflictE[j].push_back (i);//Yang ball into the trough } } inttemp=0; MEMSET (linker,-1,sizeof(linker)); for(intI=1; i<=n; i++)//Hungary biggest match{memset (Vis,0,sizeof(VIS)); if(Dfs (i)) temp++; } ans=min (ans,n-temp); if(ans==0) Break; } while(Next_permutation (pos+2, pos+n+1)); printf ("%d\n", ans); } } return 0;}
HDU 5727 Necklace Binary Chart Hungary largest match,