HDU 5727 Necklace two points + match

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.