Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
743 B
1
Indexable
Never
#include<iostream>
using namespace std;

int n,ans;
int map[100][100];
int bangmau[100];

bool checkmau(int num, int color)
{
		for (int i=0; i<n; i++)
		{
			if (map[num][i] == 1)
			{
				if (color == bangmau[i]) return false;
			}
		}
		return true;
}


void backtrack(int num)
{
	if (num == n) 
	{
		ans++;
		return;
	}
	for (int i=1; i<=4; i++)
	{
		if (checkmau(num,i))
		{
			bangmau[num] = i;
			backtrack(num+1);
			bangmau[num] = 0;
		}
	}
}


int main()
{
	int t;
	cin >> t;
	for (int tc=1;tc<=t; tc++)
	{
		cin >> n;
		for (int i=0; i<n; i++)
			for (int j=0; j<n; j++)
				cin >> map[i][j];

		ans = 0;
		backtrack(0);
		cout << "Case #" << tc << endl << ans << endl;
	}

}