Topic Portal
1 /*2 Test instructions: Put a battery in a matrix, meet the ranks of up to only one fort, unless there is a wall (X) apart, ask the maximum number of batteries to put3 Search (DFS): Data small, 4 * 4 can be used DFS, starting from (0,0), go to (n-1,n-1) left lower corner, x = cnt/n; y = cnt% n; Update coordinates,4 until all the points are gone, as you go from the left to the right, just determine whether the upper left side of the current point satisfies the condition.5 Note: The current point can not be the case of the blasting table should also consider6 G[x][y] = = ' O '; Errors for half a day before checking out:)7 */8#include <cstdio>9#include <iostream>Ten#include <cstring> One#include <string> A#include <algorithm> -#include <map> -#include <cmath> the using namespacestd; - - Const intMAXN = 1e4 +Ten; - Const intINF =0x3f3f3f3f; + Charg[5][5]; - intans; + intN; A at BOOLOkintXinty) - { - for(inti=y-1; i>=0; --i) - { - if(G[x][i] = ='o')return false; - Else if(G[x][i] = ='X') Break; in } - for(inti=x-1; i>=0; --i) to { + if(G[i][y] = ='o')return false; - Else if(G[i][y] = ='X') Break; the } * $ return true;Panax Notoginseng } - the voidDFS (intCntinttot) + { A if(CNT = = n *N) the { + if(Ans < tot) ans =tot; - return ; $ } $ - Else - { the intx = CNT/N; - inty = cnt%N;Wuyi the if(G[x][y] = ='.'&& ok (x, y) = =true) - { WuG[x][y] ='o'; -DFS (cnt+1, tot+1); AboutG[x][y] ='.'; $ } - -DFS (cnt+1, tot); - } A } + the intMainvoid)//ZOJ 1002/hdoj 1045 Fire Net - { $ //freopen ("zoj_1002.in", "R", stdin); the the while(SCANF ("%d", &n) = =1&&N) the { the for(intI=0; i<n; ++i) -scanf ("%s", &g[i]); in theAns =-1; DFS (0,0); the Aboutprintf ("%d\n", ans); the } the the return 0; + } - the /*Bayi 5 the 1 the 5 - 2 - 4 the */
DFS ZOJ 1002/hdoj 1045 Fire Net