1/* 2. Use a wooden board to cover the muddy place and not the grass. Any length of wood! Overlapping overwrites are allowed! '*' Indicates the muddy place, '.' indicates the grass! 3 train of thought: 4 first let's recall the HDU 2119 matrix question. One matrix contains only 0 and 1, and then let's select a row, or 5 is a column that deletes all the rows or column 1 of the row. It takes at least a few steps to get the result? 6 7 the idea of this question is to create an edge for the row mark and column mark value 1! The Hungarian algorithm can be used to obtain the maximum number of matching 8 of the Bipartite Graph. the maximum number of matching = the minimum number of vertex overwrites! The minimum vertex overwrite is to overwrite all the edges of the Bipartite Graph with the minimum vertex, and then remove all edges from the vertices in the minimum 9 overwrite, that is, all 1 is removed! 10 11 what should I do with this question? In fact, it is similar to the above idea, but it cannot be solved on the source image! Every row or column of 12 in this question is restricted by the grass, which cannot be covered when it is covered in muddy places. Therefore, we need to ignore the influence of the grass! 13 14 solution: Connection Block
If the left and right sides of a connected area cannot be extended, it is the row connection block. If the upper and lower areas cannot be extended, it is the column connection block. The row connection block is used as the X set, and the column connection block is used as the y set, then, the edge obtained by connecting X and Y represents the Muddy area to be covered. You can use the Hungary algorithm to find the minimum connecting block required to cover all muddy areas.
1. assign different numbers (from 1... (cntr starts), that is, if 15 lawns are ignored, a total of cntr lines are connected in the muddy place! 16 2. Similarly, each column is operated by each row. A total of CNTC Column Connection blocks exist! 17. The thought of closing the question is the same as that above ..... 18 19G [I] [J] = '*' Then ar [I] [J] is the new row mark of the point, AC [I] [J] indicates the column ID of this row, which is 20 */21 # include <iostream> 22 # include <cstring> 23 # include <cstdio> 24 # include <algorithm> 25 # include <vector> 26 # define M 5527 # define n 100028 using namespace STD; 29 vector <int> V [N]; 30 char G [m] [m]; 31 int vis [N]; 32 int linker [N]; 33 int ar [m] [m], AC [m] [m]; 34 int n, m; 35 36 bool DFS (int u) {37 int Len = V [u]. size (); 38 (Int I = 0; I <Len; ++ I) {39 int vu = V [u] [I]; 40 if (! Vis [VU]) {41 vis [VU] = 1; 42 if (! Linker [VU] | DFS (linker [VU]) {43 linker [VU] = u; 44 return true; 45} 46} 47} 48 return false; 49} 50 51 int main () {52 while (scanf ("% d", & N, & M )! = EOF) {53 int cntr = 1, CNTC = 1; 54 for (INT I = 1; I <= N; ++ I) 55 scanf ("% s ", G [I] + 1); 56 for (INT I = 1; I <= N; ++ I) 57 for (Int J = 1; j <= m; + + J) 58 If (G [I] [J] = '*') {59 ar [I] [J] = cntr; 60 if (J + 1> M | G [I] [J + 1]! = '*') 61 + + cntr; 62} 63 for (Int J = 1; j <= m; ++ J) 64 for (INT I = 1; I <= N; ++ I) 65 if (G [I] [J] = '*') {66 AC [I] [J] = CNTC; 67 if (I + 1> N | G [I + 1] [J]! = '*') 68 + + CNTC; 69} 70 for (INT I = 1; I <= N; + I) 71 for (Int J = 1; j <= m; ++ J) 72 If (G [I] [J] = '*') 73 V [ar [I] [J]. push_back (AC [I] [J]); 74 75 int ans = 0; 76 memset (linker, 0, sizeof (linker); 77 for (INT I = 1; I <cntr; ++ I) {78 memset (VIS, 0, sizeof (VIS); 79 if (DFS (I) ++ ans; 80} 81 printf ("% d \ n", ANS); 82 For (INT I = 1; I <cntr; ++ I) 83 V [I]. clear (); 84} 85 return 0; 86}