This is from the Shandong University giant to learn from the practice
The total number of black balls in the enumeration is 8!, and then eight white balls are available in position with two black balls left and right there is no relationship map
This is the exact words, the specific point, each generation of the ring row, only the non-impact of the connected edge
Finally: Pay attention to a little, n number of ring row is (n-1)!
#include <stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<vector>#include<map>using namespaceStd;typedefLong LongLL;Const intinf=0x3f3f3f3f;Const intn=2e5+5;intpos[Ten],n,m,match[Ten],ret;BOOLvis[Ten],used[Ten],g[Ten][Ten],mp[Ten][Ten];BOOLDfsintu) { for(intv=1; v<=n;++v) { if(!g[u][v]| | USED[V])Continue; USED[V]=true; if(match[v]==-1||DFS (Match[v])) {Match[v]=T; return true; } } return false;}voidsolve () {memset (match,-1,sizeof(match)); Memset (g,false,sizeof(g)); for(intI=2; i<=n;++i) { for(intj=1; j<=n;++j) { if(mp[pos[i]][j]| | mp[pos[i-1]][j])Continue; G[I][J]=true; } } for(intI=1; i<=n;++i) { if(mp[pos[1]][i]| |Mp[pos[n]][i])Continue; g[1][i]=true; } intans=0; for(intI=1; i<=n;++i) {memset (used,false,sizeof(used)); if(Dfs (i)) + +ans; } ret=min (ret,n-ans);}void Get(intx) { if(ret==0)return; if(x==n+1) {solve ();return;} for(intI=1; i<=n;++i) { if(Vis[i])Continue; POS[X]=i; Vis[i]=true; Get(x+1); Vis[i]=false; }}intMain () {vis[1]=true;p os[1]=1; while(~SCANF ("%d%d",&n,&m)) { if(n==0) {printf ("0\n"); Continue; } memset (MP,0,sizeof(MP)); while(m--){ intu,v; scanf ("%d%d",&u,&v); Mp[v][u]=true; } ret=INF; Get(2); printf ("%d\n", ret); } return 0;}
View Code
HDU 5727 Necklace two points + match