#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;
char Map[10][10];
int judge(int row, int col)
{
for(int i = 0; i < 4; i++)
{
if(Map[row][i] == Map[row][col] && i != col)
{
return 0;
}
}
for(int i = 0; i < 4; i++)
{
if(Map[i][col] == Map[row][col] && i != row)
{
return 0;
}
}
int arow = row;
int acol = col;
if(row % 2 == 1)
{
row -= 1;
}
if(col % 2 == 1)
{
col -= 1;
}
for(int i = row; i <= row + 1; i++)
{
for(int j = col; j <= col + 1; j++)
{
if(Map[arow][acol] == Map[i][j] && i != arow && j != acol)
{
return 0;
}
}
}
return 1;
}
void DFS(int cnt)
{
if(cnt == 4 * 4)
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
cout << Map[i][j];
}
cout << endl;
}
return ;
}
int row = cnt / 4;
int col = cnt % 4;
if(Map[row][col] == '*')
{
for(int i = 1; i <= 4; i++)
{
Map[row][col] = i + ' 0';
if(judge(row,col) == 1)
{
DFS(cnt + 1);
}
Map[row][col] = '*';
}
}
else DFS(cnt + 1);
}
int main()
{
int T;
cin >> T;
int t = 0;
while(T--)
{
t++;
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
cin >> Map[i][j];
}
}
cout << "Case #" << t << ":" << endl;
DFS(0);
}
return 0;
}
[点击并拖拽以移动]