Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
815 B
4
Indexable
Never
int used[7][7];

void bt(int r, int c){
	if(r==6 && c==7){
		ans++;
		return;
	}

	if(!visit[r][c]){
		if(c<7 && !visit[r][c+1]){
			int num1=map[r][c];
			int num2=map[r][c+1];
			if(!used[num1][num2]){
				visit[r][c]=visit[r][c+1]=1;
				used[num1][num2]=used[num2][num1]=1;
				if(c<7){
					bt(r,c+1);
				}
				else{
					bt(r+1,0);
				}
				visit[r][c]=visit[r][c+1] = 0;
				used[num1][num2] = used[num2][num1] = 0;
			}
		}

		if(r<6 && !visit[r+1][c]){
			int num1=map[r][c];
			int num2=map[r+1][c];
			if(!used[num1][num2]){
				visit[r][c]=visit[r+1][c]=1;
				used[num1][num2]=used[num2][num1]=1;
				if(r<6){
					bt(r,c+1);
				}
				else{
					bt(r+1,0);
				}
				visit[r][c]=visit[r+1][c] = 0;
				used[num1][num2] = used[num2][num1] = 0;
			}
		}
	}
}
Leave a Comment