POJ 3041 Asteroids (minimum point coverage of the binary chart)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3041

In a n*n map, there are m and obstacles, you can eliminate a row or a row of obstacles each time, ask you to eliminate at least a few times to remove all obstacles.

Using a binary graph to connect rows (left) and columns (to the right) with obstructions, such as (2,3), there is an obstacle, then the left 2 and 3 sides on the right. The number of edges is the number of obstacles, the number of points is the number of times, so the problem becomes a little point covering all the edges, that is, the minimum point coverage problem. In a binary graph, the minimum point overwrite = maximum number of matches.

1 //minimum point overwrite = maximum match2#include <iostream>3#include <cstdio>4#include <cstring>5#include <vector>6 using namespacestd;7 Const intN =505;8 structEdge {9     intnext, to;Ten}edge[n*N]; One intHead[n], CNT, match[n]; A BOOLVis[n]; -  - voidinit () { thememset (Match,-1,sizeof(Match)); -Memset (Head,-1,sizeof(head)); -memset (Vis,false,sizeof(Vis)); -CNT =0; + } -  +InlinevoidAddintU,intv) { AEdge[cnt].next =Head[u]; atEdge[cnt].to =v; -Head[u] = cnt++; - } -  - BOOLDfsintu) { -      for(inti = Head[u]; ~i; i =Edge[i].next) { in         intv =edge[i].to; -         if(!Vis[v]) { toVIS[V] =true; +             if(Match[v] = =-1||DFS (Match[v])) { -MATCH[V] =u; the                 return true; *             } $         }Panax Notoginseng     } -     return false; the } +  A intHungry (intN) { the     intres =0; +      for(inti =1; I <= N; ++i) { -memset (Vis,false,sizeof(Vis)); $         if(Dfs (i)) $res++; -     } -     returnRes; the } - Wuyi intMain () the { -     intN, M, U, v; Wu      while(~SCANF ("%d%d", &n, &m)) { - init (); About          for(inti =0; I < m; ++i) { $scanf"%d%d", &u, &v); - Add (U, v); -         } -printf"%d\n", Hungry (n)); A     } +     return 0; the}

POJ 3041 Asteroids (minimum point coverage of the binary chart)

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.