#include <iostream>
using namespace std;
const int n=7;
//三角板的个数
//邻接矩阵,用来判断是否相邻
const int data[n][n]=
{
{0,1,0,0,1,0,1},
{1,0,0,1,0,1,0},
{0,0,0,0,1,0,1},
{0,1,1,0,0,1,1},
{1,0,0,0,0,0,1},
{0,1,0,1,0,0,0},
{1,0,1,1,1,0,0}
};
//每个板的颜色
int color[n]={0,0,0,0,0,0,0};
static int total;
int colorsame(int s)//判断与周围的三角板颜色
{
int flag=0;
for(int i=0; i<s; i++)
{
//使用邻接矩阵判断是否相邻
//如果相邻判断颜色是否相同
if(data[i][s]==1 && color[i]==color[s])
flag=1;
}
return flag;
}
void output()//输出涂色方案
{
for(int i=0; i<n; i++)
{
cout<<color[i]<<" ";
}
total++;
cout<<endl;
}
void tryfind(int s)//查找涂色方案的递归
{
if(s==n)
output();
else
{
//1、2、3、4代表四种颜色
//只有与周围三角块的颜色不同时才会进入下一个三角板的涂色
for(int i=1; i<=4; i++)
{
color[s]=i;
if(colorsame(s)==0)
tryfind(s+1);
}
}
}
int main()
{
total=0;
tryfind(0);
cout<<total<<endl;
return 0;
}
02-28
12-07
1346
07-03
1096
11-09
986