/*dfs, you need to be aware of the format of the input test data. */
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cstddef>5#include <iterator>6#include <algorithm>7#include <string>8#include <locale>9#include <cmath>Ten#include <vector> One#include <cstring> A#include <map> -#include <utility> -#include <queue> the#include <stack> -#include <Set> - using namespacestd; - Const intINF =-0x3f3f3f3f; + Const intMAXN = -; - Const intModprime =3046721; + A intN; at intcolorarr[Ten]; - Charimap[Ten][Ten]; - intAnswer =0; - - BOOLIsadjoincolor (intNodeintcolor) - { in for(inti =0; I < n; ++i) - { to if((imap[node][i] = ='1') && (color = =Colorarr[i])) + { - return true; the } * } $ return false;Panax Notoginseng } - the voidSolve (intnodenum) + { A if(Nodenum = =N) the { +++answer; - return; $ } $ for(intcolor =1; Color <=4; ++color) - { - if(!isadjoincolor (nodenum, color)) the { -Colorarr[nodenum] =color;WuyiSolve (Nodenum +1); theColorarr[nodenum] =-1; - } Wu } - } About $ - intMain () - { - #ifdef HOME AFreopen ("inch","R", stdin); + //freopen ("Out", "w", stdout); the #endif - $Fill (Colorarr, Colorarr +Ten, -1); theCIN >>N; the for(inti =0; I < n; ++i) the { the for(intj =0; J < N; ++j) - { inCIN >>Imap[i][j]; the } the } AboutSolve (0); thecout << Answer <<Endl; the the + #ifdef HOME -Cerr <<"Time Elapsed:"<< clock ()/Clocks_per_sec <<"Ms"<<Endl; the _CrtDumpMemoryLeaks ();Bayi #endif the return 0; the}
Depth First search Code[vs] 11,164 color problems