Given a checker, if a piece is placed at a certain point, there is not enough other pieces in the row and column of the piece unless there is a wall between them. Now, given a chessboard containing walls and open spaces, ask how many pieces can be placed at most.
Solution: All ". "Points are saved. If two points are not in the same row and are not in the same column, an edge is connected between the two points. Otherwise, the two points are separated by a wall. If yes, the edge is connected, otherwise, you can find the largest group.
The Code is as follows:
# Include <iostream> # include <cstdlib> # include <cstring> # include <cstdio> using namespace STD; int N, Nd [20], idx, G [20] [20]; char MP [10] [10]; bool check (int A, int B) {int X1 = Nd [a]/n, y1 = Nd [a] % N; int X2 = Nd [B]/n, y2 = Nd [B] % N; If (x1! = X2 & Y1! = Y2) return true; If (x1 = x2) {// if it is in the same row for (INT I = Y1 + 1; I <Y2; ++ I) {If (MP [X1] [I] = 'X') {return true ;}} else if (Y1 = Y2) {for (INT I = X1 + 1; I <X2; ++ I) {If (MP [I] [Y1] = 'X ') {return true ;}}return false;} void build () {memset (G, 0, sizeof (g); For (INT I = 0; I <idx; ++ I) {for (Int J = I + 1; j <idx; ++ J) {G [I] [J] = G [J] [I] = check (I, j) ;}} int ret, CNT [20], St [2 0]; void DFS (int x, int num) {for (INT I = x + 1; I <idx; ++ I) {If (! G [x] [I]) continue; If (CNT [I] + num <= RET) return; int flag = true; For (Int J = 0; j <num; ++ J) {If (! G [I] [st [J]) {flag = false; break ;}} if (FLAG) {st [num] = I; DFS (I, num + 1) ;}}if (Num> RET) {ret = num;} int query () {ret = 0; For (INT I = idx-1; i> = 0; -- I) {st [0] = I; DFS (I, 1); CNT [I] = ret;} return ret;} int main () {While (scanf ("% d", & N), n) {idx = 0; For (INT I = 0; I <n; ++ I) {scanf ("% s", MP [I]); For (Int J = 0; j <n; ++ J) {If (MP [I] [J] = '. ') {Nd [idx ++] = I * n + J ;}} build (); printf ("% d \ n", query ());} return 0 ;}