Pagini recente » Cod sursa (job #2376303) | Cod sursa (job #710396) | Cod sursa (job #3165329) | Cod sursa (job #699110) | Cod sursa (job #993747)
Cod sursa(job #993747)
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
char ch[12];
bool a[12][12];
int n,sol,u[12],g[12];
vector<int> gr[12];
void back(int k,int ng)
{
if(k>n)
{
if(ng<2) return;
memset(u,0,sizeof(u));
for(int i=1;i<=ng;++i)
{
for(int j=0;j<(int)gr[i].size();j++)
for(int k=1;k<=n;k++)
if(a[gr[i][j]][k]==1)
u[g[k]]=i;
for(int j=1;j<=ng;++j)
if(u[j]!=i&&i!=j)
return;
}
sol++;
return;
}
for(int i=1;i<=ng;++i)
{
gr[i].push_back(k); g[k]=i;
back(k+1,ng);
gr[i].pop_back(); g[k]=0;
}
gr[ng+1].push_back(k); g[k]=ng+1;
back(k+1,ng+1);
gr[ng+1].pop_back(); g[k]=0;
}
int main()
{
freopen("copii.in","r",stdin);
freopen("copii.out","w",stdout);
scanf("%d",&n);getchar();
for(int i=1;i<=n;i++)
{
gets(ch+1);
for(int j=1;j<=n;j++)
a[i][j]=ch[j]-'0';
}
back(1,0);
printf("%d\n",sol);
return 0;
}