#include <iostream>
using namespace std;
static int total;
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,0},
{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};
void output()
{
cout<<"serial number: ";
for(int i=0; i<n; i++)
{
cout<<color[i]<<" ";
}
total++;
cout<<endl;
}
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 tryFind(int s)
{
if(s==n)
output();
else
{
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="<<total<<endl;
return 0;
}
using namespace std;
static int total;
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,0},
{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};
void output()
{
cout<<"serial number: ";
for(int i=0; i<n; i++)
{
cout<<color[i]<<" ";
}
total++;
cout<<endl;
}
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 tryFind(int s)
{
if(s==n)
output();
else
{
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="<<total<<endl;
return 0;
}