Untitled

 avatar
unknown
plain_text
2 years ago
833 B
5
Indexable
#include<iostream>
using namespace std;
int N;
int map[1000][1000];
int visit[1000];
int dem;
void nhap(){
	for(int i=0; i<N;i++){
		for(int j=0; j<N;j++){
			cin>>map[i][j];
		}
	}
}
void reset(){
	for(int i=0; i<N;i++){
		visit[i]=-1;
	}
}
bool check(int x){
	for(int i=0; i<N; i++){
		if(map[x][i]==1 && visit[i]==visit[x])
			return false;
	}
	return true;
}

void dequy(int x){
	if(x==N){
		dem++;
		return;
	}
	for(int i=0 ; i<4;i++){
		visit[x]=i;
		if(check(x)){
			dequy(x+1);
		}
		visit[x]=-1;
	}
}
int main()
{
	int test_case;
	int T;
	freopen("text.txt", "r", stdin);
	cin >> T;
	for(test_case = 1; test_case <= T; ++test_case)
	{
		cin>>N;
		reset();
		nhap();
		dem=0;
		dequy(0);	
		cout << "Case #" << test_case   << endl;
		cout<< dem<<endl;
	}
	return 0;
}
Editor is loading...