POJ 2724 purifying Machine (binary graph Max match)

Source: Internet
Author: User
Tags switches

Test instructions

There are 2^n cheese, numbered 00 ... 0 to 11.. 1.

There is a machine with n switches. Each switch can be set to 0 or 1, or set *. However, there can be a maximum of one switch set in n switches *.

Once the machine's switch is turned on, the machine will disinfect the numbered cheese of the state according to the state of the N switches.

For example: 111----disinfect the cheese with number 111. Description: * represents 0 or 1. For example: 1*1----disinfect the cheese with numbers 101 and 111.

Now some of the cheese is contaminated. Give me the number of these cool cheese.

Ask for at least a few times to set the machine so that all the cheese is disinfected.

Ideas:

A state with * can be used to disinfect two pieces of cheese. If both cheeses are not poisoned by the previous operation, this state can reduce the number of machine operations. So the state of the belt * must be operated.

We should try to find the state as much as possible, the two pieces of cheese that have been sterilized in each state have not been poisoned by other * 's operations. The binary graph model is looming.

To disinfect the milk cool copy one, one on the left, one on the right, if the left set of a cheese number and the right set of a piece of cheese number one, then they can be sterilized by one operation.

The maximum matching m of the binary graph is obtained.

Answer: Number of pieces of cheese to sterilize-M/2

* (unresolved): There is a thing do not know how to pass. This is the biggest match why must be twice times the relationship.

Not likely to exist: hypothesis (1-2,3 2-1,3 3-1,2) (1-2,3,4 2-1,3,4 3-1,2,4 4-1,2,3)

1-2 2-3 3-1 such a situation. (correct should be 1-2 2-1) or 1-2 2-3 3-4 4-1 (although can be adjusted to 1-2 2-1 3-4 4-3)

Code:

intn,m,c;Chars[ the];BOOLex[2005];intnum[2005];vector<int> graph[2005];BOOLbmask[2005];intcx[2005],cy[2005];intFindpath (intu) {    intL=graph[u].size (); Rep (I,0, L-1){        intv=Graph[u][i]; if(!Bmask[v]) {Bmask[v]=true; if(cy[v]==-1||Findpath (Cy[v])) {Cy[v]=u; Cx[u]=v; return 1; }        }    }    return 0;}intMaxmatch () {intans=0; Rep (I,1, c) cx[i]=cy[i]=-1; Rep (I,1Cif(cx[i]==-1) {mem (Bmask,false); Ans+=Findpath (i); }    returnans;}BOOLOnedigit (intXinty) {    intf=0;  while(x| |y) {f+ = ((x&1)! = (y&1)); X>>=1, y>>=1; }    if(f==1)        return true; Else        return false;}intMain () { while(SCANF ("%d%d", &n,&m)!=eof,n| |m) {Mem (ex,false); C=0; Rep (I,1,2*m) graph[i].clear (); Rep (I,1, M) {scanf ("%s", s); intts1=0, ts2=0; Rep (J,0, N-1) {Ts1*=2; ts2*=2; if(s[j]!='*') ts1+= (s[j]-'0'), ts2+= (s[j]-'0'); Elsets1+=0, ts2+=1; }            if(!ex[ts1]) {num[++c]=ts1; ex[ts1]=true; } if(!ex[ts2]) {num[++c]=ts2; ex[ts2]=true; } } Rep (I,1, c) Rep (J,1, C) {            if(Onedigit (Num[i],num[j])) Graph[i].push_back (j); }        intDd=maxmatch ()/2; printf ("%d\n", C-DD); }}

POJ 2724 purifying Machine (binary graph Max 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.