POJ 1231 (simple search)

Nothing, note the details 
// # the include <bits / STDC ++ H.> #Include <the iostream> #include <cstdio> #include <CString> #define INF (0x3f3f3f3f) the using namespace STD; const int MAXN = 16; char Grape [MAXN] [MAXN]; BOOL VIS [MAXN]; int n-, K, ANS; void DFS (Row int, int NUM) { IF (NUM == K) { ++ ANS; return; } IF (Row> n- ) return; for (int I =. 1; I <= n-; I ++) { ! IF (Grape [Row] [I] == '#' && VIS [I]) {// for each map is not I visited node VIS [I] = to true; DFS (Row +. 1, NUM +. 1); view [i] = false; } } DFS (Row +. 1, NUM); // (SB, the hold flag is not required when the position possible) out outside the loop, looking for a long time n, has TLE } int main () { iOS :: sync_with_stdio (to false); cin.tie (0), cout.tie (0); the while (CIN >> >> n-K) { IF (n-== -. 1) BREAK; for (int I =. 1; I <= n- ; I ++) for (int. 1 = J; J <= n-; J ++) CIN >> Grape [I] [J]; Memset (VIS, to false, the sizeof (VIS)); // for each column ans = 0; DFS (1,0); COUT ANS << << '\ n-'; } }

  

Guess you like

Origin www.cnblogs.com/newstartCY/p/11620201.html