Question: There are t chess pieces in the square of N * M. Ask how many guns can be placed at most, and each gun cannot attack each other (the gun can be fired)
Gun: There is a pawn in the middle of the same row or column.
# Include <stdio. h> # include <iostream> # include <algorithm> # include <string. h> # include <queue> # include <math. h> # define M 50 # define ll long using namespace STD; int n, m, T, ans; int ma [m] [m]; bool BFS (int x, int y) // judge whether x, y can put {int xx = X-1; int CNT = 0; while (XX> = 0) {If (MA [XX] [Y] = 1 & CNT = 1) return false; if (MA [XX] [Y] = 1 | ma [XX] [Y]) CNT ++; xx --;} xx = x + 1; CNT = 0; while (XX <n) {If (MA [XX] [Y] = 1 & CNT = 1) return false; If (MA [XX] [Y] = 1 | ma [XX] [Y]) CNT ++; XX ++;} int YY = Y-1; CNT = 0; while (yy> = 0) {If (MA [x] [YY] = 1 & CNT = 1) return false; if (MA [x] [YY] = 1 | ma [x] [YY]) CNT ++; YY --;} YY = Y + 1; CNT = 0; while (yy <m) {If (MA [x] [YY] = 1 & CNT = 1) return false; if (MA [x] [YY] = 1 | ma [x] [YY]) CNT ++; YY ++;} return true ;} void DFS (int x, int y, int TMP) {If (TMP> ans) ans = TMP; For (INT I = x; I <n; I ++) {for (Int J = 0; j <m; j ++) {if (I = x & J <Y) contin UE; If (MA [I] [J]! =-1 & BFS (I, j) {ma [I] [J] = 1; DFS (I, j + 1, TMP + 1 ); ma [I] [J] = 0 ;}}} int main () {While (~ Scanf ("% d", & N, & M, & T) {memset (MA, 0, sizeof (MA); int X, Y; while (t --) {scanf ("% d", & X, & Y); MA [x] [Y] =-1 ;}ans = 0; DFS (0, 0); printf ("% d \ n", ANS );}}