/*
dfs,需要注意输入的测试数据的格式。
*/
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> 10 #include <vector> 11 #include <cstring> 12 #include <map> 13 #include <utility> 14 #include <queue> 15 #include <stack> 16 #include <set> 17 using namespace std; 18 const int INF = -0x3f3f3f3f; 19 const int MaxN = 55; 20 const int modPrime = 3046721; 21 22 int n; 23 int colorArr[10]; 24 char imap[10][10]; 25 int answer = 0; 26 27 bool isAdjoinColor(int node, int color) 28 { 29 for (int i = 0; i < n; ++i) 30 { 31 if ((imap[node][i] == '1') && (color == colorArr[i])) 32 { 33 return true; 34 } 35 } 36 return false; 37 } 38 39 void Solve(int nodeNum) 40 { 41 if (nodeNum == n) 42 { 43 ++answer; 44 return; 45 } 46 for (int color = 1; color <= 4; ++color) 47 { 48 if (!isAdjoinColor(nodeNum, color)) 49 { 50 colorArr[nodeNum] = color; 51 Solve(nodeNum + 1); 52 colorArr[nodeNum] = -1; 53 } 54 } 55 } 56 57 58 int main() 59 { 60 #ifdef HOME 61 freopen("in", "r", stdin); 62 //freopen("out", "w", stdout); 63 #endif 64 65 fill(colorArr, colorArr + 10, -1); 66 cin >> n; 67 for (int i = 0; i < n; ++i) 68 { 69 for (int j = 0; j < n; ++j) 70 { 71 cin >> imap[i][j]; 72 } 73 } 74 Solve(0); 75 cout << answer << endl; 76 77 78 #ifdef HOME 79 cerr << "Time elapsed: " << clock() / CLOCKS_PER_SEC << " ms" << endl; 80 _CrtDumpMemoryLeaks(); 81 #endif 82 return 0; 83 }