Cod sursa(job #997504)
#include<fstream>
using namespace std;
int n,teams,t[12],sol;
char mat[12][12];
inline void Verif()
{
if(teams<2)
return;
int i,j;
bool ok[12][12];
for(i=1;i<=teams;i++)
for(j=1;j<=teams;j++)
ok[i][j]=false;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(mat[i][j]=='1')
ok[t[i]][t[j]]=true;
for(i=1;i<=teams;i++)
for(j=i+1;j<=teams;j++)
if(!ok[i][j] || !ok[j][i])
return;
sol++;
}
inline void Back(int pas)
{
if(pas==n+1)
Verif();
else
{
for(int i=1;i<=teams;i++)
{
t[pas]=i;
Back(pas+1);
}
teams++;
t[pas]=teams;
Back(pas+1);
teams--;
}
}
int main()
{
int i;
ifstream fin("copii.in");
fin>>n;
for(i=1;i<=n;i++)
fin>>(mat[i]+1);
fin.close();
teams=1;
t[1]=1;
Back(2);
ofstream fout("copii.out");
fout<<sol<<"\n";
fout.close();
return 0;
}