Cod sursa(job #2218309)
Utilizator | tudor P ptudor | Data | 4 iulie 2018 11:14:10 |
---|---|---|---|
Problema | Copii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.84 kb |
#include <bits/stdc++.h>
using namespace std;
int n;
int st[11];
int f=0;
int fr[11];
int m[11][11];
void rst()
{
int i;
for (i=1;i<=n;i++)
fr[i]=0;
}
void Check()
{
int i,j;
int x;
int ch=1;
int M=0;
for (i=1;i<=n;i++)
if (st[i]>M)
M=st[i];
for (x=1;x<=M&&ch==1;x++)
{
rst();
ch=1;
for (i=1;i<=n;i++)
{
if (st[i]==x)
{
for (j=1;j<=n;j++)
{
if (m[i][j]==1)
fr[st[j]]=1;
}
}
}
for (j=1;j<=M;j++)
{
if (fr[j]==0&&j!=x)
{
ch=0;
}
}
}
if (ch==1)
f++;
}
int l=1;
void Back(int i,int x,int b)
{
if (i>n)
{
if (l==0)
{
if (b==1)
{
if (x<n)
Back(1,x+1,0);
else
Check();
}
else
Check();
}
else
l=0;
}
else
{
if (st[i]==x)
{
Back(i+1,x,1);
}
else
if (st[i]>x)
{
st[i]=x;
Back(i+1,x,1);
st[i]=i;
if (i<n||b==1)
Back(i+1,x,b);
}
else
Back(i+1,x,b);
}
}
ifstream in("copii.in");
char c[11];
void input()
{
int i,j;
in.get();
for (i=1;i<=n;i++)
{
in.getline(c,10);
for (j=1;j<=n;j++)
{
m[i][j]=c[j-1]-48;
}
}
}
int main()
{
ofstream out("copii.out");
in>>n;
int i,j;
for (i=1;i<=n;i++)
st[i]=i;
input();
Back(1,1,1);
out<<f<<"\n";
}