Pagini recente » Cod sursa (job #155392) | Cod sursa (job #2865006) | Cod sursa (job #2139660) | Cod sursa (job #425817) | Cod sursa (job #2482147)
#include <fstream>
#include <cstring>
#include <vector>
#define nmax 11
using namespace std;
ifstream fin("copii.in");
ofstream fout("copii.out");
int x[12],mx[12];
int cnt=0;
int ct;
int graf_copii[nmax][nmax];
bool verif(int k)
{
int echipa[nmax];
int n=0;
n=mx[ct];
if(n==1) return 0;
int graf_echipe[nmax][nmax]={0};
for(int i=1; i<=ct; ++i)
for(int j=1; j<=ct; ++j)
if(x[i]!=x[j] && graf_copii[i][j]==1)
{
graf_echipe[x[i]][x[j]]=1;
}
/*
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
fout<<graf_echipe[i][j]<<" ";
fout<<"\n";
}
fout<<"\n";
*/
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=n; ++j)
{
if(i!=j && graf_echipe[i][j]==0) return 0;
}
}
return 1;
}
void Back(int k)
{
for(int i=1; i<=mx[k-1]+1; ++i)
{
x[k]=i;
if(i<mx[k-1]) mx[k]=mx[k-1];
else mx[k]=i;
if(k==ct)
{
if(verif(k)) ++cnt;
}
else Back(k+1);
}
}
int main()
{
fin>>ct;
for(int i=0; i<ct; ++i)
{
char s[nmax];
fin>>s;
int ct_str=strlen(s);
for(int j=0; j<ct_str; ++j)
{
graf_copii[i+1][j+1]=s[j]-'0';
}
}
x[1]=1; mx[1]=1;
Back(2);
fout<<cnt;
return 0;
}