"POJ 3020" antenna Placement
The maximal independent set problem of binary graphs
' O ' means that the break point requires that all * connections be connected to one or two consecutive lines per route *
The maximum match can satisfy only the longest path that can be formed by only two consecutive connections, and the points that are not connected need to be circled separately.
i.e. N (total * number)-m (maximum match) +m (maximum match)/2
(due to the fact that the maximum match that is obtained by a bidirectional path actually represents the total number of points connected after 22 connections)
The code is as follows:
#include <cstdlib>#include <cstdio>#include <cstring>#include <iostream>using namespace STD;Charmap[ A][ -];BOOLmp[555][555],vis[555];inttp,n,link[555];intDirx[] = {-1,0,1,0};intDiry[] = {0, -1,0,1};intdir[4];BOOLCanintP) {intI,j; for(i =0; I <4; ++i) {if(P + Dir[i] <0&& p + dir[i] >= N)Continue; j = p + dir[i];if(!vis[j] && mp[p][j]) {Vis[j] =true;if(Link[j] = =-1|| Can (Link[j])) {link[j] = p;return 1; } } }return 0;}intMain () {intH,t,w,i,j,k,xx,yy,cnt,sum;scanf("%d", &t); while(t--) {memset(MP,false,sizeof(MP)); TP =0;scanf("%d%d", &h,&w); for(i =1; I <= H; ++i) {scanf('%s ', map[i]+1); } n = h*w; dir[0] =-W; dir[1] = -1; dir[2] = W; dir[3] =1; sum = n; for(i =1; I <= H; ++i) { for(j =1; J <= W; ++J,++TP) {if(Map[i][j] = =' O ') {sum--;Continue; } for(k =0; K <4; ++k) {xx = i + dirx[k]; yy = j + Diry[k];if(TP + dir[k] >=0&& TP + Dir[k] < n) {if(Map[xx][yy] = =' * ') Mp[tp][tp+dir[k]] =true; } } } }memset(link,-1,sizeof(link)); CNT =0; for(i =0; I < n; ++i) {memset(Vis,0,sizeof(VIS));if(Can (i)) cnt++; }printf("%d\n", sum-cnt+cnt/2); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"POJ 3020" antenna Placement