Binary graph matching (Hungarian algorithm) POJ 3020 Antenna Placement

Source: Internet
Author: User

Topic Portal

1 /*2 Test Instructions: * The point occupy can incidentally occupy four directions of a *, ask at least how many3 Hungarian algorithm: According to the parity of the coordinates of the * divided into two sets, then in addition to the matching one side is incidentally occupied outside, the other will occupy4 */5#include <cstdio>6#include <algorithm>7#include <cstring>8#include <vector>9 using namespacestd;Ten  One Const intMAXN = 4e2 +Ten; A Const intINF =0x3f3f3f3f; - Chars[ -][ One]; - intha[ -][ One]; the BOOLVIS[MAXN]; - intLK[MAXN]; -vector<int>G[MAXN]; - intdx[4] = {-1,1,0,0}; + intdy[4] = {0,0, -1,1}; - intun, vn; +  A BOOLDFS (intu) at { -      for(intI=0; I<g[u].size (); ++i) -     { -         intv =G[u][i]; -         if(!Vis[v]) -         { inVIS[V] =true; -             if(Lk[v] = =-1||DFS (Lk[v])) to             { +LK[V] = u;return true; -             } the         } *     } $ Panax Notoginseng     return false; - } the  + intHungaryvoid) A { the     intres =0; memset (LK,-1,sizeof(LK)); +      for(intI=1; i<=un; ++i) -     { $memset (Vis,false,sizeof(Vis)); $         if(DFS (i)) res++; -     } -  the     returnRes; - }Wuyi  the intMainvoid)//POJ 3020 Antenna Placement - { Wu     //freopen ("poj_3020.in", "R", stdin); -  About     intT scanf ("%d", &t); $      while(t--) -     { -         intH, W; scanf ("%d%d", &h, &W); -          for(intI=1; i<=h; ++i) A         { +scanf ("%s", S[i] +1); the         } -  $Un = VN =0; the          for(intI=1; i<=h; ++i) the         { the              for(intj=1; j<=w; ++j) the             { -                 if(S[i][j] = ='*') in                 { the                     if((I+J) &1) Ha[i][j] = + +un; the                     ElseHA[I][J] = + +vn; About                 } the             } the         } the  +          for(intI=1; i<=un; ++i) g[i].clear (); -  the          for(intI=1; i<=h; ++i)Bayi         { the              for(intj=1; j<=w; ++j) the             { -                 if(S[i][j] = ='*'&& (I+J) &1) -                 { the                      for(intk=0; k<4; ++k) the                     { the                         inttx = i + dx[k];intTy = j +Dy[k]; the                         if(TX >=1&& TX <= h && Ty >=1&& Ty <= w && s[tx][ty] = ='*') - G[ha[i][j]].push_back (Ha[tx][ty]); the                     } the                 } the             }94         } the  theprintf ("%d\n", UN + VN-Hungary ()); the     }98  About     return 0; -}

Binary graph matching (Hungarian algorithm) POJ 3020 Antenna Placement

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.