Dichotomy Chart "template"

Source: Internet
Author: User

Binary diagram: The vertex of the original G can be classified into two sets X and Y, all of the two vertices of the border are exactly one of the set X, and the other belongs to the set Y, which is said to be a two-point figure.
Binary graph matching: given a binary graph G, in a sub-figure m of G, any two edges in M's edge set are not attached to the same vertex, that is, a vertex has at most one edge. is called M is a match.
Binary Graph Max match: The match with the most number of edges in the graph is called the maximum match of the graph.
The binary chart is perfectly matched: if all points are on the matching edge, then the maximum match is called the perfect match.
Two-figure multiple-match: The binary graph matches a one-to-two match, where an element in set Y is allowed to match multiple elements in the set X (typically with a maximum limit of n), but the elements in collection X can only match multiple elements in the set Y.
The best match of the binary graph: The binary graph is weighted, and the maximum matching of the total weights is found in the graph.
Minimum point coverage for a binary diagram: Minimum coverage requires a minimum number of points (either x or Y sets) to have each edge associated with at least one of the points.
Binary graph minimum point coverage = two min. graph maximum Match
Minimum side overlay of a binary diagram: Select the fewest edges to allow all points in the graph to be overwritten.
The minimum side overlay of the binary graph = the non-direction graph is repeated two times, ans = N-Maximum number of matches/2
Minimum path overlay for a DAG graph: Overlay a directed acyclic graph with as few disjoint simple paths as possible
(DAG) All vertices of G, which is the minimum path coverage problem for the DAG graph.
Minimum path overwrite = number of nodes n maximum number of matches
The maximum independent set of the binary graph: A number of points are selected in Figure g of N points, so that there is no edge between the several points 22, and the maximum value of the points is calculated.
Maximum number of independent sets of binary graphs = number of nodes (n)-Maximum number of matches (m)
Typically bidirectional, it is repeated two times, ans = N-Maximum number of matches/2

Binary graph maximum matching-Hungarian algorithm Dfs edition:

Const intMAXN = -;BOOLMAP[MAXN][MAXN];BOOLBMASK[MAXN];intNx,ny;intCX[MAXN],CY[MAXN];intFindpath (intu) { for(inti =1; I <= NY; ++i) {if(Map[u][i] &&!bmask[i]) {Bmask[i] =1;if(Cy[i] = =-1||                  Findpath (Cy[i])) {Cy[i] = u; Cx[u] = i;return 1; }          }      }return 0; }intMaxmatch () {intres =0; for(inti =1; I <= NX; ++i) Cx[i] =-1; for(inti =1; I <= NY; ++i) Cy[i] =-1; for(inti =1; I <= NX; ++i) {if(Cx[i] = =-1)          { for(intj =1; J <= NY; ++J) Bmask[j] =0;          Res + = Findpath (i); }      }returnRes//Returns the maximum number of matches}

Binary graph multiple matching:

Const intMAXN = -;//maximum number of verticesintMAP[MAXN][MAXN];//Two-minute chartBOOLMASK[MAXN];//array of flags when looking for an augmented pathintNx,ny,n;//nx Left collection vertex number, NY right collection vertex numberintVCY[MAXN];//vcy[i] Represents the number of vertices of the right collection I vertex matching to the left collectionintCY[MAXN][MAXN];//cy[i][j] Represents the first J element that matches the I vertex of the right collectionintLIMIT[MAXN];each vertex of the right collection matches the maximum number of left collection vertices///can also be limit, which represents the maximum number of common constraints that match the left collection vertex, and a binary search for the answer if the element is to be askedBOOLFindpath (intU//Search for augmented paths{ for(inti =1; I <=5; ++i) {if(Map[u][i] &&! Mask[i]) {Mask[i] =1;if(Vcy[i] < limit[i])//vcy[i] < limit{cy[i][vcy[i]++] = u;return true; } for(intj =0; J < Vcy[i]; ++J)//j < Vcy[i]{if(Findpath (Cy[i][j])) {Cy[i][j] = u;return true; }            }        }    }return false;}voidMulmatch ()//Find multiple matches{intAns =0;memset(VCY,0,sizeof(VCY)); for(inti =1; I <= N; ++i) {memset(Mask,0,sizeof(Mask)); Ans + = Findpath (i);//Calculate right to match the number of points        /* IF (!        Findpath (i)) return false; */}//return true;    if(Ans = = N)printf("T-shirts rock!\n");Else        printf("I ' d rather not wear a shirt anyway...\n");}

The best matching--km algorithm of binary graph:

#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace STD;Const intMAXN = the;Const intINF =0xffffff0;intN,nx,ny;intLINK[MAXN],LX[MAXN],LY[MAXN],SLACK[MAXN];intVISX[MAXN],VISY[MAXN];//MarkintMAP[MAXN][MAXN];//Storage weight value//lx[],ly[] Top label; link[] Record matching valueintFindpath (intU//backtracking to find the optimal solution{Visx[u] =1; for(inti =1; I <= NY; ++i) {if(Visy[i])Continue;inttemp = Lx[u] + ly[i]-map[u][i];if(temp = =0)//if (map[u][i] = = Lx[u] + ly[i])//description is an equal sub-graph{Visy[i] =1;if(Link[i] = =-1|| Findpath (Link[i])) {Link[i] = u;return 1; }        }Else if(Slack[i] > Temp) slack[i] = temp; }return 0;}intKM ()//The best match for the highest weighted value{memset(Ly,0,sizeof(ly));memset(link,-1,sizeof(link)); for(inti =1; I <= NX; ++i) {Lx[i] =-inf;///for minimum right matching then lx[i] = INF         for(intj =1; J <= NY; ++J)if(Map[i][j] > Lx[i])//min Right match change symbolLx[i] = Map[i][j]; } for(inti =1; I <= NX; ++i) { for(intj =1; J <= NY; ++J) Slack[j] = INF; while(1)        {memset(VISX,0,sizeof(VISX));memset(Visy,0,sizeof(Visy));if(Findpath (i)) Break;intD = INF; for(intj =1; J <= NY; ++J)if(!visy[j] && d > slack[j]) d = slack[j];if(d = = INF)return; for(intj =1; J <= NX; ++J)if(Visx[j]) lx[j]-= D;//The minimum weight is changed to lx[j] + = D;             for(intj =1; J <= NY; ++J)if(Visy[j]) ly[j] + = D;//The minimum weight value is changed to ly[j]-= D;                ElseSLACK[J]-= D; }    }intres =0; for(inti =1; I <= NY; ++i)if(Link[i] >-1) Res + = Map[link[i]][i];returnRes//Output best match for maximum weights and}intMain () {intN while(~scanf("%d", &n)) {NX = NY = N; for(inti =1; I <= N; ++i) for(intj =1; J <= N; ++J)scanf("%d", &map[i][j]);printf("%d\n", KM ()); }return 0;}

Dichotomy Chart "template"

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.